Dmitrii
Dmitrii

Reputation: 1257

Cannot connect to the ManagementScope via C#. Access denied

I'm trying to connect to the ManagementScope as follows:

ManagementScope scope = new ManagementScope( @"\\mydomain\root\RSOP\Computer"));
scope.Connect();

But an exception (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) is thrown if the current user is not a domain administrator. How can a simple domain user connect to this management scope?

Thanks.

Upvotes: 3

Views: 8312

Answers (2)

Mohammad Arshad Alam
Mohammad Arshad Alam

Reputation: 9862

try this.....

ConnectionOptions con = new ConnectionOptions();
                  con.Username = "Administrator";
                  con.Password = "Password";

ManagementScope scope = new ManagementScope(@"\\" + strIPAddress + @"\root\cimv2", con);
                scope.Connect();

Upvotes: 4

Kev
Kev

Reputation: 119846

Unfortunately you can't without elevating the domain user's privileges.

If you were writing a deployable application you could sandbox WMI access in a Windows Service hosting a WCF or Remoting application.

This service would be configured to run under an account with sufficient rights to access WMI. Your WCF/Remoting application would expose whatever functionality or data you need access to via wrapper methods. These methods could be called by client applications without elevated rights.

Upvotes: 1

Related Questions