I was using some code to try to count the number of processors in .NET 2.0:
internal static int GetNumberOfProcessors()
{
List<string> list = new List<string>();
ManagementClass mgmt = new ManagementClass("Win32_Processor");
foreach (ManagementObject obj in mgmt.GetInstances())
{
string item = obj.Properties["SocketDesignation"].Value.ToString();
if (!list.Contains(item))
{
list.Add(item);
}
}
return list.Count;
}
and it blew up like this:
[ManagementException: Access denied ]
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) +377984
System.Management.ManagementScope.InitializeGuts(Object o) +654
System.Management.ManagementScope.Initialize() +162
System.Management.ManagementObject.Initialize(Boolean getObject) +492
System.Management.ManagementClass.GetInstances(EnumerationOptions options) +122
System.Management.ManagementClass.GetInstances() +6
This code runs fine locally on cassini, but blows up on our beta server. Anyone have any idea what to do about this?
Ok, I hate answering my own question, but I found this: http://support.microsoft.com/kb/317012 and it does seem to work.
You have to specifically modify your CIMV2 permissions, and I had to do it for the specific user, not ASPNET. Once this is on, you can use the System.Management code to count processors etc.
I really don't like how obscure this was. Microsoft needs to update those exceptions. When the System.Management class fails like that it should give detailed info on which permissions need activated for the code to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With