I found a nice Powershell function on GitHub which uses the WindowsInstaller.Installer COM object to query applications installed and lists all the details and properties quite beautifully. However, I don't want to use Powershell I want to create an exe.
I don't want to search the registry and I don't want to use WMI. I want to use the same exact method used in the powershell script and another vbscript I found. There does exist a COM object called WindowsInstaller.Installer. It definitely exists and yet for some reason I can't find a single example of how it would be accessed after importing the msi.dll in Visual Studio using C#.
Does anyone know the answer to this question?
In Visual Studio, the WindowsInstaller.Installer reference from adding the COM reference for WindowsInstaller is just a type and nothing more. It contains no method called "GetType" and trying to convert this PowerShell to C# is not working right.
I also don't know what @{} means but I guess it means Hashtable.
My sad attempt at forcing the situation below:
private void Form1_Load(object sender, EventArgs e)
{
Type installerType = Type.GetType("WindowsInstaller.Installer");
Installer installerObj = (Installer)Activator.CreateInstance(installerType);
WindowsInstaller.Installer installer = installerObj as WindowsInstaller.Installer;
var type = installer.GetType();
var Products = type.InvokeMember("Products", System.Reflection.BindingFlags.GetProperty, null, installer, null) as IEnumerable<object>;
foreach (var product in Products)
{
Hashtable hash = new Hashtable();
hash.Add("ProductCode", product);
string[] Attributes = { "Language", "ProductName", "PackageCode", "Transforms", "AssignmentType", "PackageName", "InstalledProductName", "VersionString", "RegCompany", "RegOwner", "ProductID", "ProductIcon", "InstallLocation", "InstallSource", "InstallDate", "Publisher", "LocalPackage", "HelpLink", "HelpTelephone", "URLInfoAbout", "URLUpdateInfo" };
foreach (var attribute in Attributes)
{
object[] thing = { product, attribute };
var details = type.InvokeMember("ProductInfo", System.Reflection.BindingFlags.GetProperty, null, installer, thing);
hash.Add(attribute, details);
}
new ??????????
}
}