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
Solved

cpu count

Posted on 2004-08-31
14
536 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
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…
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…

837 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