--
Thanks.
"Saucer Man" <sauc...@nospam.net> wrote in message
news:uLnKelwi...@TK2MSFTNGP04.phx.gbl...
> What's the best way to get the number of processors? I was thinking of
> just getting it from the environment variable.
If WMI is an option then this may be a start:
Sub main()
MsgBox "Count processors=" & CountProcessors & vbCrLf & _
"Query processors=" & QueryProcessors & vbCrLf & _
"Logical Processors=" & QueryLogicalProcessors
End Sub
Public Function CountProcessors() As Long
Dim oWMI As Object
Dim cCPUs As Object
Set oWMI = GetObject("winmgmts://./root/cimv2")
Set cCPUs = oWMI.execquery("Select * from Win32_Processor")
CountProcessors = cCPUs.Count
Set cCPUs = Nothing
Set oWMI = Nothing
End Function
Public Function QueryProcessors() As Long
Dim oWMI As Object
Dim cCPUs As Object
Dim oCPU As Object
Set oWMI = GetObject("winmgmts://./root/cimv2")
Set cCPUs = oWMI.execquery("Select NumberOfProcessors from
Win32_ComputerSystem")
For Each oCPU In cCPUs
QueryProcessors = oCPU.NumberOfProcessors
Next
Set cCPUs = Nothing
Set oWMI = Nothing
End Function
Public Function QueryLogicalProcessors() As Long
Dim oWMI As Object
Dim cCPUs As Object
Dim oCPU As Object
Set oWMI = GetObject("winmgmts://./root/cimv2")
Set cCPUs = oWMI.execquery("Select NumberOfLogicalProcessors from
Win32_ComputerSystem")
For Each oCPU In cCPUs
QueryLogicalProcessors = oCPU.NumberOfLogicalProcessors
Next
Set cCPUs = Nothing
Set oWMI = Nothing
End Function
The NumberOfLogicalProcessors vs NumberOfProcessors is discussed starting
here:
http://msdn.microsoft.com/en-us/library/aa394102(VS.85).aspx
Probably.
There is a general disdain for Environmental Variables. Mainly because they
are so easily changed for a particular session (which is preceived as a
security risk), and partly they just don't seem as cool as snooping the
Registry for system info. On the other hand, they are convenient and require
no special permissions to read.
So it depends on how critical this information is for your application, ie,
what's the downside if the User lies?
Frankly, if a system variable is available - use it. Unless you have an
overwhelming reason not to.
-ralph
>If WMI is an option then [...]
and if not, then:
Type SYSTEM_INFO
wProcessorArchitecture As Integer
wReserved As Integer
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOfProcessors As Long '<<<-------
dwProcessorType As Long
dwAllocationGranularity As Long
wProcessorLevel As Integer
wProcessorRevision As Integer
End Type
Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
[...]
Dim sInfo As SYSTEM_INFO, n As Long
GetSystemInfo sInfo
n = sInfo.dwNumberOfProcessors
[...]
I'm not 100% sure but I think that the number of logical processors is
returned here.
The official method GetLogicalProcessorInformation().
--
Dee Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
iCode Systems