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)
Solution using "net view \\servername"
I know it's not very desirable to use a console command and do some string-gymnastic on the output, but on the other hand it does work and it's not very desirable either, at least for me, to have to mess around with the DCOM default settings to to get the WMI way to work (at least on Win7s).
Has been tested on Win7 and XP clients and MS- and linux server.
I had this problem too.I was trying to write C# code to get WMI information and files from a remote PC. And ran into two
Access Denied
errors:To keep a long story short, I had to make changes to the remote PC. See below:
According to the WMI FAQ on TechNet, the 0x80070005 error indicates a DCOM issue:
(Although Windows XP is mentioned, this may be applied to Windows 7 as well.)
The 0x800706BA error, in its rurn, indicates a firewall issue:
Try enabling the Remote administration exception in Windows Firewall on the remote computer and see if it helps. To do this from the command line, run the following command in the elevated command prompt:
You can also find the DCOM, UAC, Windows Firewall and other settings required for remote WMI access in the Connecting to WMI Remotely Starting with Windows Vista article on MSDN.
Also, since Samuel is a nondomain account, you need to grant this account DCOM Remote Access, Remote Launch and Remote Activation permissions on the remote computer as described here.
You may want to check to WMI Security Settings on the Remote Windows 7 PC. Right Click Computer > Manage > Services and Applications > WMI Control > Security Tab and make sure the user account you are using has the necc permissions.
Maybe it's the missing 'EnablePrivileges':
From MSDN (ConnectionOptions.EnablePrivileges Property):
Edit: If it doesn't work, try setting the ImpersonationLevel to 'Impersonate':
You got "Access is denied." because you cannot query scope connection with username only. You have 2 options: null for username and password or enter username and password.
You got "The RPC server is unavailable." because firewall doesn't let you query that machine. You have 2 options: disable firewall or add remote administration exception to it.
You can add firewall exception like this in cmd: Older windows versions:
Newer windows versions:
If you try to login with domain user, change username to
domainName\username
or set connection propertyconnection.Authority = "ntlmdomain:domainName"
.