我正在尝试使用WMI编写一个mini w32可执行文件来远程卸载应用程序.
我可以使用下面的代码列出所有已安装的应用程序,但我找不到通过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 …Run Code Online (Sandbox Code Playgroud)