Detect multi-core with VB 2005

kzrssk

Member
Nov 13, 2005
111
0
0
Hey all,

I'm trying, in VB 2005, to programmatically figure out if a computer has multi-core support or not. The only way I've come across on the Internet is by checking HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor in the registry. However, if a computer has HyperThreading, an extra processor will show up here.

Is there a way to determine if a computer truly has at least two cores in it?

Thanks,
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Code to ID the processor type & model might work, though you'll need to keep updating that code as new CPU models are released.

It might be better to just use the registry key and treat HT CPUs as multicore.

It might also be a good idea to make make whatever multicore code you're writing be controlled by a preference setting that a user can toggle. Depending on what else a user is running, they may not want you to saturate all cores at once.

(This is sometimes presented to users as a choice of how many worker threads to allow. Depending on your code 2 threads might be faster than one even for a single-core without HT.)

One selling point of multi-core systems is that a single application generally doesn't bring Windows to a standstill, because it only maxes out one core.
 

kzrssk

Member
Nov 13, 2005
111
0
0
What I'm developing isn't actually using the processor, it's simply detecting multi-core functionality for the purpose of deciding whether or not to allow installation of a certain application. I thought about what you suggested at first, as well, but came to the same conclusion, though given the speed at which entirely new models come out, it might still work if I just do a general check for "Pentium D", "Core Duo", "Core 2 Duo", etc.
 

exdeath

Lifer
Jan 29, 2004
13,679
10
81
Gah! Don't impose installation restrictions based on what *you* deems works or not. Let the user install it and deal with it.

Maybe I know it's going to run like crap but want to run it anyway?
 

kzrssk

Member
Nov 13, 2005
111
0
0
It's not my choice. They tell me to code it like this; I do it so I can get a paycheck. Besides, our remote sites have their own budgets, so they use 6 or 7 year old computers to save money. That's mainly what this sort of thing is for.

Anyway, would you run Office 2007 on anything less? :p
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: Neverm1nd
http://msdn2.microsoft.com/en-us/library/aa394373.aspx

There's some VB script examples at the bottom of the page. Look at NumberOfCores.

Looks nice, but it doesn't work with XP or Server 2003 (or 2000, ME, 98). If the installer already requires Vista or Server 2008 that isn't a problem.

"NumberOfCores
Data type: uint32
Access type: Read-only

Number of cores for the current instance of the processor. A core is a physical processor on the integrated circuit. For example, in a dual-core processor this property has a value of 2. For more information, see Remarks.

Windows Server 2003, Windows XP, and Windows 2000: This property is not available."
 

JACKDRUID

Senior member
Nov 28, 2007
729
0
0
System.Console.WriteLine(System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"))
System.Console.Read()
 

LightningRider

Senior member
Feb 16, 2007
558
0
0
Sorry to hijack your thread a little, but does anyone know how to do this (to get System properties like CPU, amount of Memory etc) in Java?

I'm planning on doing something like that for part of a final school project coming up but we've never discussed that.
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Originally posted by: LightningRider
Sorry to hijack your thread a little, but does anyone know how to do this (to get System properties like CPU, amount of Memory etc) in Java?

I'm planning on doing something like that for part of a final school project coming up but we've never discussed that.

Yeah, look at the processor JMX bean. It's been a while since I've touched it, but I know for a fact that it allows you to see number of processors. Of course this only works with JVM 1.5 and above.
 

formulav8

Diamond Member
Sep 18, 2000
7,004
522
126
Visual Basic 2005 and Above actually has a Property that will return the core/cpu count under the Environment class.

Environment.ProcessorCount


That will give you the total cpus/cores the target computer has :)


Jason