我有安装的应用程序MSI文件。我前需要知道应用程序的的产品名称的安装开始。
I have an msi file that installs an application. I need to know the product name of that application before the installation starts.
我试过如下:
{
...
Type type = Type.GetType("Windows.Installer");
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)
Activator.CreateInstance(type);
installer.OpenDatabase(msiFile, 0); //this is my guess to pass in the msi file name...
...
}
但现在呢?类型为的空的,这引发了我的错误。而且我在哪里传中,MSI文件?
but now? Type is null, which throws me an error. And where do I pass in the name of the MSI file?
感谢您的任何提示和放大器;注释。
Thanks for any hints & comments.
您需要使用:
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
下面是我的一些code的样本 - 在我的情况,我得到了安装程序版本:
Here is a sample from some of my code - in my case I get the installer version:
// Get the type of the Windows Installer object
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
// Create the Windows Installer object
Installer installer = (Installer)Activator.CreateInstance(installerType);
// Open the MSI database in the input file
Database database = installer.OpenDatabase(inputFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
// Open a view on the Property table for the version property
View view = database.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'");
// Execute the view query
view.Execute(null);
// Get the record from the view
Record record = view.Fetch();
// Get the version from the data
string version = record.get_StringData(2);