Solved

cpu count

Posted on 2004-08-31
14
524 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 36
bit defender blocks good applications 2 93
MS Date Picker 64 bit 32 bit issue 12 53
Protecting vb6 & .Net code Obfuscation 18 121
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

813 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

17 Experts available now in Live!

Get 1:1 Help Now