G
Guest
Hi,
I can't figure it out. A piece of code to obtain the Processor ID which has
always worked fine, suddenly throws an UnauthorizedAccessException. I have
changed absolutely nothing to my code, and nothing to my system. The same
code works fine on a different computer. The code in question:
string cpuInfo = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
The exception occurs when it tries to iterate through the foreach loop and
halts on the very first iteration.
I am running this on Vista with .NET framework 2.0. Code runs fine on a
similar machine also running Vista.
Any help to point me in the right direction would be much appreciated.
Christopher Hughes
I can't figure it out. A piece of code to obtain the Processor ID which has
always worked fine, suddenly throws an UnauthorizedAccessException. I have
changed absolutely nothing to my code, and nothing to my system. The same
code works fine on a different computer. The code in question:
string cpuInfo = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
The exception occurs when it tries to iterate through the foreach loop and
halts on the very first iteration.
I am running this on Vista with .NET framework 2.0. Code runs fine on a
similar machine also running Vista.
Any help to point me in the right direction would be much appreciated.
Christopher Hughes