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 simpl开发者_Python百科e 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.
精彩评论