locked
Remote Access RRS feed

  • Question

  • Hello, I try to remote access to my second computer on the same network but i have this error message

    An unhandled exception of type 'System.UnauthorizedAccessException' occurred in System.Management.dll

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

    and this is the code

      try
                {
                    ConnectionOptions _Options = new ConnectionOptions();
                    ManagementPath _Path = new ManagementPath("\\\\192.168.1.5\\root\\CIMV2");
    
                    ManagementScope _Scope = new ManagementScope(_Path, _Options);
                    _Scope.Connect();
                    ManagementObjectSearcher srcd = new ManagementObjectSearcher("select * from Win32_DisplayConfiguration");
                    foreach (ManagementObject obj in srcd.Get())
                    {
                        //listBox5.Items.Add(obj.Properties.ToString());
                        foreach (PropertyData aProperty in obj.Properties)
                        {
                           MessageBox.Show(aProperty.Name.ToString() + " : " + aProperty.Value);
                        }
                    }
                }
                catch (ManagementException ex)
                {
                    MessageBox.Show(ex.Message);
                }

    Tuesday, December 8, 2015 8:57 PM

Answers

  • Hi ayman-at1000,

    If you want to access a remote computer without specifying credentials, the credentials of the running user will be used, so you should first make sure current user has the permissions to access the remote computer.

    If you are not in a domain environment, just try to specify credentials as below code.

    ConnectionOptions _Options = new ConnectionOptions();
    _Options.Impersonation = ImpersonationLevel.Impersonate;
    _Options.Authentication = AuthenticationLevel.Packet;
    _Options.Timeout = new TimeSpan(0, 0, 30);
    _Options.EnablePrivileges = true;
    _Options.Username = "\\";
    _Options.Password = "";
    ManagementPath _Path = new ManagementPath();
    _Path.NamespacePath = "\\\\192.168.1.5\\root\\CIMV2 ";
    _Path.Server = "";   
    ManagementScope _Scope = new ManagementScope(_Path, _Options);
    _Scope.Connect();
    ManagementObjectSearcher srcd;
    srcd = new ManagementObjectSearcher  
    (_Scope, new ObjectQuery("select * from Win32_DisplayConfiguration "));
    //…….

    Best Regards,

    Albert Zhang

    • Proposed as answer by Albert_Zhang Thursday, December 17, 2015 12:51 PM
    • Marked as answer by Kristin Xie Monday, December 21, 2015 9:05 AM
    Thursday, December 10, 2015 2:34 AM

All replies

  • isn't that message is very *obvious* ?

    have u verified all the needed permission setting?

    Wednesday, December 9, 2015 5:44 AM
  • Hi ayman-at1000,

    If you want to access a remote computer without specifying credentials, the credentials of the running user will be used, so you should first make sure current user has the permissions to access the remote computer.

    If you are not in a domain environment, just try to specify credentials as below code.

    ConnectionOptions _Options = new ConnectionOptions();
    _Options.Impersonation = ImpersonationLevel.Impersonate;
    _Options.Authentication = AuthenticationLevel.Packet;
    _Options.Timeout = new TimeSpan(0, 0, 30);
    _Options.EnablePrivileges = true;
    _Options.Username = "\\";
    _Options.Password = "";
    ManagementPath _Path = new ManagementPath();
    _Path.NamespacePath = "\\\\192.168.1.5\\root\\CIMV2 ";
    _Path.Server = "";   
    ManagementScope _Scope = new ManagementScope(_Path, _Options);
    _Scope.Connect();
    ManagementObjectSearcher srcd;
    srcd = new ManagementObjectSearcher  
    (_Scope, new ObjectQuery("select * from Win32_DisplayConfiguration "));
    //…….

    Best Regards,

    Albert Zhang

    • Proposed as answer by Albert_Zhang Thursday, December 17, 2015 12:51 PM
    • Marked as answer by Kristin Xie Monday, December 21, 2015 9:05 AM
    Thursday, December 10, 2015 2:34 AM