Get number of processors

  • Thread starter Thread starter William Stacey
  • Start date Start date
William,

There are a few alternatives. First, and probably the simplest, there is an
environment variable called "NUMBER_OF_PROCESSORS" on Windows 2000, Windows
20003, and Windows XP. You could use Environment class in the System
namespace as follows.

string strNumberOfProcessors = Environment.GetEnvironmentVariable(
"NUMBER_OF_PROCESSORS" );

Second, this information is also exposed via WMI which you could query using
classes in the System.Management namespace. The third alternative is to
call a Win32 API function, GetSystemInfo, via P/Invoke.

Hope this helps.
 
int n =
Convert.ToInt16(System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESS
ORS"));

Please note that it's not supported in Windows 95/98.
 
Thanks to both. They should hang a property off the Environment class or
other. Cheers!
 
Back
Top