Solved

cpu count

Posted on 2004-08-31
14
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11942946
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
ID: 11942970
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
ID: 11943058
hi,
first thx for your answer,  but i get a result of 4 on a pc with two cpus
mero
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:mladenovicz
ID: 11943137
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
ID: 11943138
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11943175
0
 
LVL 31

Author Comment

by:merowinger
ID: 11943276
@mladenovicz
could you write in on on code which shows only the cpus, without subs and classes....
mero
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11943379
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
ID: 11943387
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
ID: 11943399
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
ID: 11949586
@mladenovicz
i get an error when executing you code: line1 -> Instruction end expects
mero
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11949912
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
ID: 11950029
ok now it works!!!
THX
mero
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11950058
you're welcomed
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 91
VB6 - Convert HH:MM into Decimal 8 75
Sub or Function is not defined 6 59
Collapse and expand table in Word 2010 2 157
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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