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 us开发者_C百科ing 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.
Troubleshooting Error Code 80070005 - Access Denied
- Securing a Remote WMI Connection
精彩评论