我正在尝试编写一个迷你 w32 可执行文件来使用 WMI 远程卸载应用程序。
我可以使用下面的代码列出所有已安装的应用程序,但我找不到通过 WMI 和 C# 远程卸载应用程序的方法
我知道我可以使用 msiexec 作为进程来做同样的事情,但如果可能的话,我希望使用 WMI 来解决这个问题......
谢谢, Cem
static void RemoteUninstall(string appname)
{
ConnectionOptions options = new ConnectionOptions();
options.Username = "administrator";
options.Password = "xxx";
ManagementScope scope = new ManagementScope("\\\\192.168.10.111\\root\\cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Product");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
// Display the remote computer information
Console.WriteLine("Name : {0}", m["Name"]);
if (m["Name"] == appname)
{
Console.WriteLine(appname + " found and will be uninstalled... but how");
//need to uninstall this app...
}
}
}