Question: 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?

Answer: 
Looks like a permissions issue. 

If it runs fine locally (under cassini), it would be running under your credentials, which probably have local admin rights, hence the right permissions to access this data.

Make sure the code is running as a user that has sufficient permissions to get this data (if running IIS 7 and above look at the application pool identity - that would be the account running the code).
Gosh, still encounter the same issue using Aspose.Email (domain email address validation).

Here is my error message:

> 
> System.Management.ManagementException: Access denied 
>  at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
>  at System.Management.ManagementScope.InitializeGuts(Object o)
>  at System.Management.ManagementScope.Initialize()
>  at System.Management.ManagementObjectSearcher.Initialize()
>  at System.Management.ManagementObjectSearcher.Get()
>  at   .()
>  at   .()
>  at   .(String )
>  at Aspose.Email.Verify.EmailValidator.(String , Int32 )
>  at Aspose.Email.Verify.EmailValidator.(String , MailAddress , String[]& )
> 
> 
> 

And my solution for my ASP.NET application is wrap the code with 

```
using (HostingEnvironment.Impersonate()) 
{
    ...
}     

```