2

I tried using WMI, but with no success so far.

Dim objLocator As New OLEObject("WbemScripting.SWbemLocator")
Dim objService As OLEObject
objService = objLocator.ConnectServer(".", "root\cimv2")
Dim instances As OLEObject
instances = objService.InstancesOf("Win32_ComputerSystem")

Whatever I try to do next trigers an OLE exception. Is there any other known way of getting a CPU count programaticly from REALbasic. I know I could execute a vbscript from the shell class, but it's a bit too ugly for me.

Polynomial
  • 27,674
  • 12
  • 80
  • 107
Miha
  • 63
  • 4

1 Answers1

3

You can call the GetSystemInfo function and use the dwNumberOfProcessors member of the SYSTEM_INFO structure.

Have a look at the following example code:

  Declare Sub GetSystemInfo Lib "kernel32" Alias "GetSystemInfo" (lpSystemInfo As Ptr)

  Dim SystemInfo as MemoryBlock=new MemoryBlock(36)
  GetSystemInfo(SystemInfo)
  Dim ProcessorCount as Integer=SystemInfo.Long(20)

The SYSTEM_INFO structure has a size of 36 Bytes. The members before dwNumberOfProcessors have a size of 20 bytes.

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33