gpt4 book ai didi

c# - WMI - 读取远程域计算机中的 IIS 应用程序时抛出 'Access Denied' 异常

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:35 24 4
gpt4 key购买 nike

下面是我使用 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:

我尝试过的补救措施:

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

If your computer is part of a domain, connect to the target computerusing a domain account that is in the local Administrators group ofthe remote computer. Then UAC access token filtering will not affectthe domain accounts in the local Administrators group. Do not use alocal, nondomain account on the remote computer, even if the accountis in the Administrators group.

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

最佳答案

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

详细信息:Access Denied for WMI

关于c# - WMI - 读取远程域计算机中的 IIS 应用程序时抛出 'Access Denied' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27039814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com