Solved

cpu count

Posted on 2004-08-31
14
560 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
Technology Partners: 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

Technology Partners: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

729 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