Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WMI远程卸载应用程序_C#_Wmi_Uninstallation_Wmi Query - Fatal编程技术网

C# 使用WMI远程卸载应用程序

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

我正在尝试编写一个小型w32可执行文件,以便使用WMI远程卸载应用程序

我可以使用下面的代码列出所有已安装的应用程序,但我找不到通过WMI和C远程卸载应用程序的方法#

我知道我可以做同样的使用msiexec作为一个进程,但我希望解决这个使用WMI如果可能的话

谢谢, Cem

看看(微软的免费工具)-它可以用各种语言为您生成WMI代码,包括C#

下面是一个示例,演示了
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"]);
}