简体   繁体   English

仅Windows XP的WMI中的访问被拒绝问题

[英]Access Denied Problem in WMI for Windows XP only

I have been writing an application to get the details of remote machine like OS Name, Logon User Name etc using WMI Classes. 我一直在编写一个应用程序,以使用WMI类获取远程计算机的详细信息,例如OS名称,登录用户名等。

In our network we have machines with Windows XP, Windows Vista Windows 7. 在我们的网络中,我们拥有配备Windows XP,Windows Vista Windows 7的计算机。

I am able to get the informations for all windows 7 and windows vista machines. 我能够获取所有Windows 7和Windows Vista计算机的信息。

But the problem here is i am not able to get the informations for windows XP machines. 但是这里的问题是我无法获得Windows XP计算机的信息。 Every time i am getting the following exception Access is denied. 每当我遇到以下异常时, 访问都会被拒绝。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))

I have gone through the net but no help. 我已经上网了,但是没有帮助。 I have done all the steps mentioned in the following link http://support.microsoft.com/kb/875605 . 我已经完成了以下链接http://support.microsoft.com/kb/875605中提到的所有步骤。 But no luck still i am not able to solve the problem. 但是,仍然没有运气我无法解决问题。 I have domain username with administrator privilages. 我具有管理员特权的域用户名。 Below is the code that i have used. 下面是我使用的代码。 (C#) (C#)

private void GetRemoteComputerInfo(string compName)
    {
        ObjectGetOptions oc = new ObjectGetOptions();
        try {
            ConnectionOptions connOptions = new ConnectionOptions();
            connOptions.Username = "domain\\domainUserName";
            connOptions.Password = "domainUserPass";
            connOptions.Authority = "kerberos:domain\\" + compName;
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            ManagementScope msc;
            if (compName == Environment.MachineName)
                msc = new ManagementScope("\\\\" + compName + "\\root\\cimv2");
            else
                msc = new ManagementScope("\\\\" + compName + "\\root\\cimv2", connOptions);
            msc.Connect();
            ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
            mc.Scope = msc;
            //collection to store all management objects
            ManagementObjectCollection moc = mc.GetInstances();
            if (moc.Count != 0) {
                foreach (ManagementObject mo in mc.GetInstances()) {
                    Console.WriteLine(string.Format("\nMachine Make: {0}\nMachine Model: {1}  System Type: {2}  Host Name: {3}  Logon User Name: {4}{5}",
                                      mo["Manufacturer"].ToString(),
                                      mo["Model"].ToString(),
                                      mo["SystemType"].ToString(),
                                      mo["DNSHostName"].ToString(),
                                      mo["UserName"].ToString(),
                                      Environment.NewLine));
                }
            }
        }
        catch (Exception e) {
            Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
        }
    }

Please help me to solve the problem. 请帮我解决问题。

Prasad, in the past i have a similar issue related to the WMI DCOM permission, and was resolved following the instructions of these these two links. Prasad,过去我有一个与WMI DCOM权限有关的类似问题,并且已按照这两个链接的说明进行了解决。

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

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