我尝试连接到远程PC并查询其进程但是当我运行代码时,它与我的本地PC连接并获得其进程而不是远程PC。 代码是
ManagementScope scope = new ManagementScope(@"\\remote-user\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
答案 0 :(得分:0)
(我假设远程用户是完整计算机名称)更改:
ManagementScope scope = new ManagementScope(@"\\remote-user\\root\\cimv2");
为:
ManagementScope scope = new ManagementScope(@"\\<FullComputerName>\root\cimv2");
另一种选择:
ManagementScope scope = new ManagementScope("\\\\<FullComputerName>\\root\\cimv2");
请参阅this链接(这是Microsoft示例)
修改强>
如果你想与deffrent用户联系,你需要传递ConnectionOptions(见上面的链接)
答案 1 :(得分:0)
您似乎将用户名(“remote-user”)而不是远程计算机的主机名传递到管理范围。将您的代码更改为例如:
ConnectionOptions options = new ConnectionOptions();
options.Password = "remoteUserPassword"; // you may want to avoid plain text password and use SecurePassword property instead
options.Username = "remote-user";
ManagementScope scope = new ManagementScope(@"\\remoteMachineHostname\root\cimv2", options);