2010-05-06 68 views
1

这是我的代码:单击一个按钮并为remotePC采用文本框中的文本。我可以在本地运行它,但是当我尝试远程运行它时,它不起作用,我认为它与使用WMI运行共享文件有关?我正在尝试使用WMI运行命令

public void IPXFER(string RemotePC) 
{  
    object[] theProcessToRun = { @"\\network-share\ipxfer\ipxfer.exe -s corp-trend -p 1234 -m 1 -c 12345" }; 
    ConnectionOptions theConnection = new ConnectionOptions(); 
    theConnection.Impersonation = ImpersonationLevel.Impersonate; 
    theConnection.EnablePrivileges = true; 
    ManagementScope theScope = new ManagementScope("\\\\" + RemotePC + "\\root\\cimv2", theConnection); 
    ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()); 
    theClass.InvokeMethod("Create", theProcessToRun); 
} 
+0

我添加了file.copy将共享文件复制到remotepc,这很好,但是当我尝试执行批处理文件时,它不起作用。我唯一能想到的是,当wmi在不同的会话中运行这个批处理文件时? – 2010-05-06 18:09:41

回答

0

你得到了什么错误?如果它是上述错误中的一个,请参阅this链接。也看看this链接,看看你是否缺少任何东西。

+0

我没有得到任何错误,事实上,如果我将ProcessToRun更改为notepad.exe,它将运行正常,我可以在使用我的用户名运行它的过程中看到它。我认为它与WMI的网络共享有关。 – 2010-05-06 17:16:46

0

我结束了使用file.copy,然后执行与WMI开关的exe,修复了问题。

相关问题