使用WMI Win32_Process

时间:2018-03-14 17:32:15

标签: c# wmi win32-process

我没有收到任何错误,程序根本没有远程执行,我正在寻找可能发生这种情况的想法。当我使用命令提示符从远程计算机运行程序时,程序在本地运行正常。程序本身需要10个参数,因此下面是args [0]到[9]。任何建议都表示赞赏。

注意:我使用记事本测试了这段代码并且工作正常,所以它似乎与我如何使用参数调用我的程序有关(因为记事本没有参数)。

由于

String programArgs = @"C:\Report\Report.exe " + "\"" + args[0] + "\"" + " " + args[1] 
      + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + args[6] 
      + " " + "\"" + args[7] + "\"" + " " + args[8] + " " + args[9];

object[] theProcessToRun = { programArgs, @"C:\Report" };

ManagementScope wmiScope = new ManagementScope(@"\\" + hostname + @"\root\cimv2");
wmiScope.Options.Impersonation = ImpersonationLevel.Impersonate;
wmiScope.Connect();
using (ManagementClass managementClass = new ManagementClass(wmiScope, 
                           new ManagementPath("Win32_Process"), new ObjectGetOptions()))
{
    managementClass.InvokeMethod("Create", theProcessToRun);
}

0 个答案:

没有答案