Solved

cpu count

Posted on 2004-08-31
14
501 Views
Last Modified: 2008-01-09
hi experts,
how can i get the physical count of cpus in a pc.
I have a problem with the hyperthreading of the system.
So sometimes i get the result of two cpus, but it is only one (with hyperthreading).

I would be pleased, if you could solve via vbscript.

thx
mero
0
Comment
Question by:merowinger
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
Retrive the value of the environmental variable NUMBER_OF_PROCESSORS. This VB code dumps all the variable available in the environment.

Private Sub Form_Load()
Dim i As Integer
Dim txt As String

    i = 1
    Do
        If Environ(i) = "" Then Exit Do
        txt = txt & Environ(i) & vbCrLf
        i = i + 1
    Loop

    Msgbox txt
End Sub





This code should do the trick:

MsgBox Environ("NUMBER_OF_PROCESSORS")



I think you can also do the same with VBA with a little variation.
0
 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("NUMBER_OF_PROCESSORS")


See this for details: http://msdn.microsoft.com/library/en-us/script56/html/wsproenvironment.asp


0
 
LVL 31

Author Comment

by:merowinger
Comment Utility
hi,
first thx for your answer,  but i get a result of 4 on a pc with two cpus
mero
0
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Type SYSTEM_INFO
    dwOemID As Long
    dwPageSize As Long
    lpMinimumApplicationAddress As Long
    lpMaximumApplicationAddress As Long
    dwActiveProcessorMask As Long
    dwNumberOrfProcessors As Long
    dwProcessorType As Long
    dwAllocationGranularity As Long
    dwReserved As Long
End Type
Private Sub Form_Load()
    Dim SInfo As SYSTEM_INFO
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'KPDTeam@Allapi.net
    'Set the graphical mode to persistent
    Me.AutoRedraw = True
    'Get the system information
    GetSystemInfo SInfo
    'Print it to the form
    Me.Print "Number of procesor:" + str$(SInfo.dwNumberOrfProcessors)
    Me.Print "Processor:" + str$(SInfo.dwProcessorType)
    Me.Print "Low memory address:" + str$(SInfo.lpMinimumApplicationAddress)
    Me.Print "High memory address:" + str$(SInfo.lpMaximumApplicationAddress)
End Sub
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
0
 
LVL 31

Author Comment

by:merowinger
Comment Utility
@mladenovicz
could you write in on on code which shows only the cpus, without subs and classes....
mero
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
YOu should be ready to do such customization yourself. Just to help you:




Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Type SYSTEM_INFO
   dwOemID As Long
   dwPageSize As Long
   lpMinimumApplicationAddress As Long
   lpMaximumApplicationAddress As Long
   dwActiveProcessorMask As Long
   dwNumberOrfProcessors As Long
   dwProcessorType As Long
   dwAllocationGranularity As Long
   dwReserved As Long
End Type


Private Sub Form_Load()
   Dim SInfo As SYSTEM_INFO
   GetSystemInfo SInfo
   MsgBox "Number of procesor:" + str$(SInfo.dwNumberOrfProcessors)
End Sub
0
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
I just saw that you prefer script code. This is a VB code (API)
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 250 total points
Comment Utility
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)

Private Type SYSTEM_INFO
    dwOemID As Long
    dwPageSize As Long
    lpMinimumApplicationAddress As Long
    lpMaximumApplicationAddress As Long
    dwActiveProcessorMask As Long
    dwNumberOrfProcessors As Long
    dwProcessorType As Long
    dwAllocationGranularity As Long
    dwReserved As Long
End Type

Private Sub Form_Load()
    Dim SInfo As SYSTEM_INFO

    GetSystemInfo SInfo
    MsgBox "Number of procesor:" + str$(SInfo.dwNumberOrfProcessors)
End Sub
0
 
LVL 31

Author Comment

by:merowinger
Comment Utility
@mladenovicz
i get an error when executing you code: line1 -> Instruction end expects
mero
0
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
This is not VB script code, but VB. So, maybe that is your problem. Above code works fine for me from VB
0
 
LVL 31

Author Comment

by:merowinger
Comment Utility
ok now it works!!!
THX
mero
0
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
you're welcomed
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now