To update MSI property with C#,
Added reference for Microsoft.Deployment.WindowsInstaller.dll
The PropertyTable not include default value is null Propery, we can not update the value, if not in property table, we could insert the property.
using Microsoft.Deployment.WindowsInstaller;
bool isProertyExits = false ;
using (Database msi = new Database(msiFileName, DatabaseOpenMode.Transact))
{
using (var view = msi.OpenView(msi.Tables["Property"].SqlSelectString))
{
view.Execute();
Record record = view.Fetch();
while (record != null)
{
if (record.GetString(1) == ProertyName)
{
record.SetString("Value", ProertyValue);
view.Modify(ViewModifyMode.Assign, record);
msi.Commit();
isProertyExits = true;
}
record = view.Fetch();
}
}
//If not find
if (!isProertyExits) {
using (var view = msi.OpenView(msi.Tables["Property"].SqlInsertString))
{
foreach (var item in properties)
{
Record missingRecord = msi.CreateRecord(2);
missingRecord.SetString(1, ProertyName);
missingRecord.SetString(2, ProertyValue);
view.Execute(missingRecord);
msi.Commit();
}
}
}
}
No comments:
Post a Comment