简体   繁体   English

WMI管理范围连接到本地而不是远程

[英]WMI management scope connect to local instead of remote

I tried to connect to a remote PC and query for its processes but when I run the code, it got connected with my local PC and obtained its processes instead of the remote PC. 我试图连接到远程PC并查询其进程,但是当我运行代码时,它与我的本地PC连接并获得了其进程,而不是远程PC。 The code is 该代码是

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)

(I assume that remote-user is Full computer name) change: (我假设远程用户是计算机的全名)更改:

ManagementScope scope = new ManagementScope(@"\\remote-user\\root\\cimv2");

to: 至:

ManagementScope scope = new ManagementScope(@"\\<FullComputerName>\root\cimv2");

another option: 另外一个选项:

ManagementScope scope = new ManagementScope("\\\\<FullComputerName>\\root\\cimv2");

See this link (it's Microsoft example) 查看链接(这是Microsoft的示例)

Edit 编辑

if you want to connect with deffrent user you need to pass ConnectionOptions (see above link) 如果您想连接不同的用户,则需要传递ConnectionOptions(请参见上面的链接)

You appear to be passing a username ("remote-user") instead of a hostname of the remote machine to your management scope. 您似乎正在将用户名(“远程用户”)而不是远程计算机的主机名传递到管理范围。 Change your code to eg: 将代码更改为例如:

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);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM