How to set custom property in a msi file on the fly? I do not want to pass the custom property using msiexec. I want to save the value of the property in the msi file itself based on user log in.
Thanks in advance.
How to set custom property in a msi file on the fly? I do not want to pass the custom property using msiexec. I want to save the value of the property in the msi file itself based on user log in.
Thanks in advance.
See the USERNAME property. The only options for setting a property are: at authoring time; at the command line (directly or in a transform); and in a custom action. However the information you want may be in one of the properties set by the system.
You can use the following piece of code (after you download the WindosInstaller class written by Ian Schoen Mahr Mariano
from here
http://www.codeproject.com/KB/cs/msiinterop/msiinterop.zip
public static bool ChangeProperty(string MsiPath, string property, string value)
{
bool result = true;
IntPtr view = IntPtr.Zero;
IntPtr dataBase = IntPtr.Zero;
MsiError err;
try
{
err = MsiInterop.MsiOpenDatabase(MsiPath, MsiDbPersistMode.Transact, out dataBase);
if (err == MsiError.Success)
{
string sql = "INSERT INTO Property (Property, Value) VALUES ('" + property + "', '" + value + "')";
err = MsiInterop.MsiDatabaseOpenView(dataBase, sql, out view);
err = MsiInterop.MsiViewExecute(view, IntPtr.Zero);
if (err == MsiError.FunctionFailed)
{
string sqlUpdate = @"UPDATE Property SET Value = '" + value + "' WHERE Property = '" + property + "'";
err = MsiInterop.MsiDatabaseOpenView(dataBase, sqlUpdate, out view);
err = MsiInterop.MsiViewExecute(view, IntPtr.Zero);
}
}
err = MsiInterop.MsiDatabaseCommit(dataBase);
}
catch
{
result = false;
}
finally
{
err = MsiInterop.MsiViewClose(view);
err = MsiInterop.MsiCloseHandle(dataBase);
}
return result;
}