C# 使用WMI远程卸载应用程序
我正在尝试编写一个小型w32可执行文件,以便使用WMI远程卸载应用程序 我可以使用下面的代码列出所有已安装的应用程序,但我找不到通过WMI和C远程卸载应用程序的方法# 我知道我可以做同样的使用msiexec作为一个进程,但我希望解决这个使用WMI如果可能的话 谢谢, Cem 看看(微软的免费工具)-它可以用各种语言为您生成WMI代码,包括C# 下面是一个示例,演示了C# 使用WMI远程卸载应用程序,c#,wmi,uninstallation,wmi-query,C#,Wmi,Uninstallation,Wmi Query,我正在尝试编写一个小型w32可执行文件,以便使用WMI远程卸载应用程序 我可以使用下面的代码列出所有已安装的应用程序,但我找不到通过WMI和C远程卸载应用程序的方法# 我知道我可以做同样的使用msiexec作为一个进程,但我希望解决这个使用WMI如果可能的话 谢谢, Cem 看看(微软的免费工具)-它可以用各种语言为您生成WMI代码,包括C# 下面是一个示例,演示了Win32\u Product.Uninstall方法的用法。您需要知道要卸载的应用程序的GUID、名称和版本,因为它们是Win32
Win32\u Product.Uninstall
方法的用法。您需要知道要卸载的应用程序的GUID、名称和版本,因为它们是Win32\u产品
类的关键属性:
...
ManagementObject app =
new ManagementObject(scope,
"Win32_Product.IdentifyingNumber='{99052DB7-9592-4522-A558-5417BBAD48EE}',Name='Microsoft ActiveSync',Version='4.5.5096.0'",
null);
ManagementBaseObject outParams = app.InvokeMethod("Uninstall", null);
Console.WriteLine("The Uninstall method result: {0}", outParams["ReturnValue"]);
如果您有关于应用程序的部分信息(例如,只有名称或名称和版本),您可以使用选择
查询来获取相应的Win32\u进程
对象:
...
SelectQuery query = new SelectQuery("Win32_Product", "Name='Microsoft ActiveSync'");
EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.ReturnImmediately = true;
enumOptions.Rewindable = false;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, options);
foreach (ManagementObject app in searcher.Get())
{
ManagementBaseObject outParams = app.InvokeMethod("Uninstall", null);
Console.WriteLine("The Uninstall method result: {0}", outParams["ReturnValue"]);
}
Wi32的产品类有一个卸载方法,在网络中很少有C++和Posi壳示例,但是在C语言中,我找不到使用Wi32的产品类的一个例子和文档。顺便说一下,至少有两个关于使用WMI卸载远程应用程序的问题(带有示例代码):抱歉占用您的时间,我想我在寻找答案的时候有点累了,心烦意乱。无论如何,谢谢你的帮助。我的朋友,很多人都投你的票!!我不知道有这样的工具存在。
...
SelectQuery query = new SelectQuery("Win32_Product", "Name='Microsoft ActiveSync'");
EnumerationOptions enumOptions = new EnumerationOptions();
enumOptions.ReturnImmediately = true;
enumOptions.Rewindable = false;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, options);
foreach (ManagementObject app in searcher.Get())
{
ManagementBaseObject outParams = app.InvokeMethod("Uninstall", null);
Console.WriteLine("The Uninstall method result: {0}", outParams["ReturnValue"]);
}