简体   繁体   中英

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.

try this.....

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM