Access Denied Exception Using WMI

I am working on WMI. I want to access remote system information. The following code works for loopback or localhost, but when I try to access a remote computer, it shows the following exception error:

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

When the switch is used between 2 systems.

and

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

When both systems are directly connected.


OS on both systems: Windows Service Pack 2.
Firewalls = blocked.
Remote procedure = start.

Tool: .NET Visual Studio 2008 C #

the code:

try
{
    ConnectionOptions _Options = new ConnectionOptions();
    ManagementPath _Path = new ManagementPath(s);

    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)
        {
            listBox1.Items.Add(aProperty.Name.ToString() + " : " + aProperty.Value);
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
+2
source share
4 answers

. , , , ( , ).

, , .

, .

:

ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.Packet;
co.Timeout = new TimeSpan(0, 0, 30);
co.EnablePrivileges = true;
co.Username = "\\";
co.Password = "";

ManagementPath mp = new ManagementPath();
mp.NamespacePath = @"\root\cimv2";
mp.Server = "";               ///Regard this!!!!

ManagementScope ms = new ManagementScope(mp, co);
ms.Connect();

ManagementObjectSearcher srcd;
srcd = new ManagementObjectSearcher  
(
    ms, new ObjectQuery("select * from Win32_DisplayConfiguration")
);

.

, , ManagementPath. ControlPath, , . , .

- mabra

+3

, ManagementScope, . , ? ConnectionOptions, ManagementObjectServer .

Try:

ManagementObjectSearcher srcd;
srcd = new ManagementObjectSearcher  
(
    _Scope, new ObjectQuery("select * from Win32_DisplayConfiguration")
);

MSDN.

0

, SO asp classic - IIS WMI ASP.

, ( " Windows" ) , IIS WMI, , :

Access to the root \ WebAdministration namespace was denied because the namespace is labeled RequiresEncryption, but a script or application tried to connect to this namespace with an authentication level below Pkt_Privacy. Change the authentication level to Pkt_Privacy and run the script or application again.

The answer proposed @mabra this question, appropriate inspiration. Here is a sample C # code I added that seems to have solved this problem for me:

ConnectionOptions options = new ConnectionOptions();
options.Authentication = AuthenticationLevel.PacketPrivacy;
ManagementScope managementScope = new ManagementScope(@"\\remote-server\root\WebAdministration", options);
// ...
0
source

All Articles