Get product name from msi file in C #

I have a msi file that installs the application. I need to know the product name of this application before starting the installation.

I tried the following:

{ ... 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... ... } 

but now? The type is null, which generates an error. And where do I pass the MSI file name?

Thanks for any tips and comments.

+5
source share
3 answers

You need to use:

  Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer"); 

Here is an example from 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); 
+6
source

Wouldn't it be easier to use this code:

Type type = typeof(Windows.Installer);

If you prefer an overload of Type.GetType (String), you must specify the correct assembly name after the full class path, for example:

Type type = Type.GetType("Windows.Installer, <assembly for MsiInstaller>");

+2
source

Where did you get the "Windows.Installer" stuff from?

... because:

  • Type.GetType accepts a .NET type name, not COM ProgId.
  • Windows Installer (at least in Windows 2003) does not have a ProgId.

In short: use P / Invoke ( DllImport , etc.) to talk to the MSI API.

+1
source

Source: https://habr.com/ru/post/890521/


All Articles