【发布时间】:2013-01-13 14:34:10
【问题描述】:
我有这个代码:
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", sHost), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = "notepad.exe";
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
当我将 sHost 设置为我的本地 IP 地址时,它可以工作并打开记事本。 但是,当我将其设置为远程服务器时,什么也没有发生。
(我能够连接到远程计算机并从我的应用程序复制文件 - 这只是为了尝试远程运行东西。防火墙也已针对 WMI 进行了配置)。
有点没有更多的想法......
谢谢。
【问题讨论】:
-
我假设您已经检查了记事本没有在远程计算机的后台运行(查看任务管理器)?您没有连接到已登录用户的桌面会话,因此它可能不会显示在屏幕上。
-
感谢您的回复。是的,我检查了,但没有运行它不会在后台运行。我还尝试将用户名和密码设置为“connOptions”,但仍然没有...
-
你能检查 outParams["returnValue"] 和 outParams["processId"] 的值吗?
-
哦,现在可以了...我必须将权限添加到“connOptions”才能进入域。现在运行正常!现在的问题是 Rhumborl 首先提到的 - 进程在后台运行(可以在任务管理器中显示)。有什么办法吗?此外,“记事本”就是一个例子,实际上我正在运行一个批处理脚本。当脚本完成时,“cmd”会在后台运行..有什么办法克服它吗?谢谢!!
标签: c# wmi remote-server