在远程计算机上执行命令

时间:2014-05-02 19:16:38

标签: c# wmi

ManagementScope scope = new ManagementScope( "\\\my_server\\root\\cimv2");
scope.Connect();

如何在my_server d:\ tools上运行批处理文件?我试过了:

ManagementScope scope = new ManagementScope( "\\\my_server\\d\\tools"); 

但它似乎不起作用。

1 个答案:

答案 0 :(得分:3)

您需要使用Win32_Process类。

以下是其使用示例:http://msdn.microsoft.com/en-us/library/ms257364(v=vs.80).aspx

示例:

ManagementClass processClass = new ManagementClass(@"\\<remotecomputername>\root\cimv2:Win32_Process");
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

inParams["CommandLine"] = "calc.exe";
inParams["CurrentDirectory"] = @"c:\windows\system32";

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);