简体   繁体   中英

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.

In our network we have machines with Windows XP, Windows Vista Windows 7.

I am able to get the informations for all windows 7 and windows vista machines.

But the problem here is i am not able to get the informations for windows XP machines. Every time i am getting the following exception Access is denied. (Exception from 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 . 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#)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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