• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Detect multi-core with VB 2005

kzrssk

Member
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,
 
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.
 
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.
 
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?
 
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? 😛
 
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."
 
System.Console.WriteLine(System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"))
System.Console.Read()
 
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.
 
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.
 
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
 
Back
Top