我在GitHub上找到一个很好的Powershell函数nice Powershell function,它使用WindowsInstaller.Installer COM对象查询安装的应用程序,并列出所有详细信息和属性。但是,我不想使用Powershell,我想创建一个exe。
我不想搜索注册表,也不想使用WMI。我想使用与powershell脚本和我找到的另一个vbscript相同的方法。确实存在一个名为WindowsInstaller.Installer的COM对象。它肯定存在,但出于某种原因,在使用C#导入msi.dll的Visual Studio中,找不到如何访问它的单个示例。
有人知道这个问题的答案吗?
在Visual Studio中,通过添加WindowsInstaller的COM引用的WindowsInstaller.Installer引用只是一种类型,没有“GetType”方法,尝试将此PowerShell转换为C#不起作用。
我也不知道
下面是我强制情况的悲伤尝试:
我不想搜索注册表,也不想使用WMI。我想使用与powershell脚本和我找到的另一个vbscript相同的方法。确实存在一个名为WindowsInstaller.Installer的COM对象。它肯定存在,但出于某种原因,在使用C#导入msi.dll的Visual Studio中,找不到如何访问它的单个示例。
有人知道这个问题的答案吗?
在Visual Studio中,通过添加WindowsInstaller的COM引用的WindowsInstaller.Installer引用只是一种类型,没有“GetType”方法,尝试将此PowerShell转换为C#不起作用。
我也不知道
@ {}
表示什么,但我猜它表示Hashtable。下面是我强制情况的悲伤尝试:
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 ??????????
}
}