Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processor Count

Status
Not open for further replies.

TheLad

Technical User
Aug 3, 2001
3,846
GB
Guys

I am playing around with Scriptomatic and the processor count because we have a script that is supposed to count the number of processors in a machine but it always double counts processors that are dual core.

For example, my laptop has 1 x Dual Core processor but it shows up as two instances in Device Manager. The script also picks up two instances.

Is there a proper way of scripting this so that the correct physical number of processors is displayed?

TIA

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Give this a try. Note I am testing on Vista which does have some additions in WMI over XP so I cannot be certain if this will work for you on other OSes.

Code:
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
  WScript.Echo "AddressWidth: " & objItem.AddressWidth
  WScript.Echo "Architecture: " & objItem.Architecture
  WScript.Echo "Caption: " & objItem.Caption
  WScript.Echo "CpuStatus: " & objItem.CpuStatus
  WScript.Echo "DeviceID: " & objItem.DeviceID
  WScript.Echo "Family: " & objItem.Family
  WScript.Echo "Manufacturer: " & objItem.Manufacturer
  WScript.Echo "MaxClockSpeed: " & objItem.MaxClockSpeed
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "NumberOfCores: " & objItem.NumberOfCores
  WScript.Echo "NumberOfLogicalProcessors: " & objItem.NumberOfLogicalProcessors
  WScript.Echo
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks for the reply. I tested it on XP and it does indeed skip some of the functions, in particular NumberOfCores and NumberOfLogicalProcessors

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top