windows 无法通过 C# 连接到 ManagementScope。拒绝访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4267440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:39:47  来源:igfitidea点击:

Cannot connect to the ManagementScope via C#. Access denied

c#.netasp.netwindowsactive-directory

提问by Dmitrii

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

我正在尝试按如下方式连接到 ManagementScope:

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?

Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)如果当前用户不是域管理员,则会抛出异常 ( )。一个简单的域用户如何连接到这个管理范围?

Thanks.

谢谢。

回答by Arshad

try this.....

尝试这个.....

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

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

回答by Kev

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

不幸的是,您不能不提升域用户的权限。

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

如果您正在编写可部署的应用程序,您可以在托管 WCF 或远程处理应用程序的 Windows 服务中沙箱WMI 访问。

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.

此服务将配置为在具有访问 WMI 的足够权限的帐户下运行。您的 WCF/Remoting 应用程序将公开您需要通过包装器方法访问的任何功能或数据。这些方法可以由没有提升权限的客户端应用程序调用。