WMI - 在远程域机器中读取 IIS 应用程序时引发“拒绝访问”异常

Posted

技术标签:

【中文标题】WMI - 在远程域机器中读取 IIS 应用程序时引发“拒绝访问”异常【英文标题】:WMI - 'Access Denied' exception thrown while reading IIS applications in remote domain machine 【发布时间】:2014-11-20 12:37:00 【问题描述】:

下面是我使用 WMI 在域中读取远程计算机中的 IIS 应用程序的代码。

var connOptions = new ConnectionOptions
                                  
                                      Username = "USERNAME",
                                      Password = "PASSWORD",
                                      Authority = "ntlmdomain:DOMAINNAME",
                                      EnablePrivileges = true,
                                      Impersonation = ImpersonationLevel.Impersonate
                                  ;

var scope = new ManagementScope(@"\\SERVERNAME\root\WebAdministration", connOptions);

var WMIQuery = new ObjectQuery("SELECT * FROM Application");
var searcher = new ManagementObjectSearcher(scope, WMIQuery);

//Connect to WMI
scope.Connect();

//Write the list of Applications info 
foreach (ManagementObject queryObj in searcher.Get())

    Console.WriteLine("SiteName: 0 - 1", queryObj["SiteName"], queryObj["Path"]);

它失败并出现以下异常:

System.Management.ManagementException was caught
  Message=Access denied 
  Source=System.Management
  StackTrace:
       at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementObjectSearcher.Get()
       at Program.Main(String[] args) 
  InnerException: 

我尝试过的补救措施:

    我遵循了Handling Remote Connections Under UAC 中给出的建议,但没有成功。 引用它:

如果您的计算机是域的一部分,请连接到目标计算机 使用本地管理员组中的域帐户 远程计算机。那么UAC访问令牌过滤就不会影响 本地管理员组中的域帐户。不要使用 远程计算机上的本地非域帐户,即使该帐户 属于管理员组。

    在计算机管理 -> 服务和应用程序 -> WMI 控件 -> 查看属性 -> 导航到 Root/WebAdministration -> 安全中添加并分配给用户完全控制权。

【问题讨论】:

【参考方案1】:

通过将 ConnectionOptions 的 Authentication 属性设置为 'AuthenticationLevel.PacketPrivacy' 解决

详情在:Access Denied for WMI

【讨论】:

以上是关于WMI - 在远程域机器中读取 IIS 应用程序时引发“拒绝访问”异常的主要内容,如果未能解决你的问题,请参考以下文章

WMI:“RPC 服务器不可用”错误仅适用于域用户

远程运行 wmi 进程,没有适当的域用户权限

JNI - WMI连接错误

如何在不同域中的远程服务器上启动或停止IIS-8.5网站

尝试使用 SWbemLocator 从远程计算机检索 WMI 时访问被拒绝 (80070005)

使用C#远程设置IIS AppPool用户的文件权限