Remote WMI connection

2020-02-26 09:55发布

I want to connect to remote PC running Windows 7, from another PC using ManagementScope on a local network. On remote PC I've created a new user account "Samuel" without password and set as administrator.

ConnectionOptions options = new ConnectionOptions();
options.Username = "Samuel";
options.Password = "";

ManagementScope scope = new ManagementScope("\\\\192.168.0.2\\root\\cimv2", options);          
scope.Connect();

The Error I get:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Update:
After setting password for the use, I get new error:

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

标签: c# wmi
9条回答
一夜七次
2楼-- · 2020-02-26 10:20

Try to add domain or computer name before the username (e.g. @"mshome\Samuel").

查看更多
forever°为你锁心
3楼-- · 2020-02-26 10:24

Not sure if it is denied because the WMI engine isn't listening on the remote machine, or if you have other login/connection issues.

Here's the code I used to connect to my remote machine, and it is working perfectly. Maybe it will help you:

ConnectionOptions oConn = new ConnectionOptions();
ManagementScope oScope = null;

oConn.Username = txtLogin;
oConn.Password = txtPassword;
oConn.Authority = "ntlmdomain:" + txtDomain;

oScope = new ManagementScope("\\\\" + txtHostName + "\\root\\CIMV2", oConn);

oScope.Connect();

If my domain/login/password trio are accepted, then Connect() will work. Otherwise, Connect() throws an exception. As long as the specified credentials have permission on that machine, you should be off and running.

查看更多
Juvenile、少年°
4楼-- · 2020-02-26 10:27

Are you sure you can make remote WMI connections to accounts without passwords?

There are a number of things such accounts can't do (share files, remote desktop, for example). Try setting a password and see if that makes a difference.

查看更多
登录 后发表回答