简体   繁体   English

无法使用WMI访问远程计算机的硬件信息:拒绝访问

[英]Can't access hardware info of remote computer with WMI: Access is denied

I am trying to create an application that uses WMI to retrieve information about a computer on my local network. 我正在尝试创建一个使用WMI来检索有关本地网络上计算机信息的应用程序。 When I run it, I get an access denied error. 运行它时,出现访问被拒绝错误。 Here is the code: 这是代码:

 private void GetHDDdetails()
{
    ConnectionOptions options = new ConnectionOptions();
    options.Username = "username";
    options.Password = "password";
    options.Impersonation = ImpersonationLevel.Impersonate;
    ManagementScope oMs = new ManagementScope("\\\\remoteHostName\\root\\cimv2", options);
    ObjectQuery oQuery = new ObjectQuery("SELECT Size FROM Win32_DiskDrive");
    ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
    ManagementObjectCollection oCollection = oSearcher.Get();


    foreach (ManagementObject obj in oCollection)
    {
        hddBox.Text = obj["Size"].ToString();
    }
}

I have replaced some of the info above, such as user name and password, with placeholders for this post. 我已用本文的占位符替换了上面的一些信息,例如用户名和密码。 Some of the things I have tried is this: Disabling firewall on both machines, making sure TCP NetBIOS service and RCP and WMI services are running on both. 我尝试过的一些操作是:在两台计算机上都禁用防火墙,确保TCP NetBIOS服务以及RCP和WMI服务都在两者上运行。 The account I am using is an administrator on the local computer. 我使用的帐户是本地计算机上的管理员。 Everything I have found online tells me to check these, but it is obviously something else. 我在网上找到的所有内容都告诉我进行检查,但这显然是另外一回事。 If someone can point me in the right direction, that would be great. 如果有人可以指出我正确的方向,那就太好了。

Please check using wbemtest that you can access the information from remote machine. 请使用wbemtest检查是否可以从远程计算机访问信息。 And i hope you are replacing remoteHostName properly. 我希望您remoteHostName正确替换remoteHostName And make changes to authentication level, if you can. 如果可以,请更改身份验证级别。

scope.Options.EnablePrivileges = true;
scope.Options.Authentication = AuthenticationLevel.PacketPrivacy;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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