tags:

views:

113

answers:

5

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)

+1  A: 

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.

Will Dean
AFter setting a password i get this error":The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
shlomjmi
+1  A: 

Maybe it's the missing 'EnablePrivileges':

scope.Options.EnablePrivileges = true;

From MSDN:

ConnectionOptions.EnablePrivileges Property

Gets or sets a value indicating whether user privileges need to be enabled for the connection operation. This property should only be used when the operation performed requires a certain user privilege to be enabled (for example, a machine restart).

Edit: If it doesn't work, try setting the ImpersonationLevel to 'Impersonate':

scope.Options.Impersonation = System.Management.ImpersonationLevel.Impersonate;

ImpersonationLevel Impersonate: Impersonate-level COM impersonation level that allows objects to use the credentials of the caller. This is the recommended impersonation level for WMI calls.

weberph
A: 
  • According to the WMI FAQ on TechNet, the 0x80070005 error indicates a DCOM issue:

    0x80070005 (DCOM ACCESS_DENIED)
    This error occurs when the connected user is not recognized or is restricted in some fashion by the remote server (for example, the user might be locked out). This happens most often when accounts are in different domains. Recent changes to WMI security can also cause this error to occur:

    • Blank passwords, formerly permitted, are not allowed in Windows XP and Windows Server 2003.

    • WMI does not allow asynchronous callbacks to a Windows 98 client. A call like SWbemServices.ExecNotificationQueryAsync from a Windows 98 computer to a Windows XP computer will result in an Access Denied error returned to the Windows 98 machine.

    • The DCOM configuration access setting might have been changed.

    • If the target computer is running Windows XP, the Forceguest value under the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa might be set to force the Guest account off (value is zero).

    (Although Windows XP is mentioned, this may be applied to Windows 7 as well.)

  • The 0x800706BA error, in its rurn, indicates a firewall issue:

    0x800706xx (DCOM RPC error)
    This often occurs when a firewall is configured on the remote computer. You will need to open the appropriate ports on the firewall to permit remote administration using DCOM.

    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:

    netsh advfirewall firewall set rule group="remote admin" new enable=yes
    


    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.

Helen
as I commented the previous answer: After setting a password i get this error":The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
shlomjmi
@shlomjmi: Try enabling the *Remote administration* exception in Windows Firewall on the remote computer and see if it helps. (See updated answer.)
Helen
A: 

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

SKINDER
A: 

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.

TooFat
I don't have such option there...
shlomjmi