3

Title pretty much explains it all. I need to get some hardware information such as CPU info, and total RAM with VB6. Ideally, it would return something like this for the CPU:

Intel Core 2 Quad Q8500 2.66 GHz

and for the RAM something simple like an integer for the amount of MB the computer has total.

qJake
  • 16,821
  • 17
  • 83
  • 135

3 Answers3

6

in plain C, if interested:

#include <intrin.h>

int cpuInfo[4] = {-1};
char CPUBrandString[0x40];

memset(CPUBrandString, 0, sizeof(CPUBrandString));

__cpuid(cpuInfo, 0x80000002);
memcpy(CPUBrandString, cpuInfo, sizeof(cpuInfo));

__cpuid(cpuInfo, 0x80000003);
memcpy(CPUBrandString + 16, cpuInfo, sizeof(cpuInfo));

__cpuid(cpuInfo, 0x80000004);
memcpy(CPUBrandString + 32, cpuInfo, sizeof(cpuInfo));
Thomas
  • 303
  • 2
  • 7
  • 2
    The CPU brand string is not guaranteed to end with a null terminator, so `CPUBrandString` should be 0x41 characters long, not 0x40, if it is going to be used in any context where null terminated strings are expected. – Polynomial Sep 06 '22 at 00:25
  • Would be nice to show an example output – p0358 Sep 21 '22 at 02:55
  • To answer myself: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz – p0358 Sep 21 '22 at 03:26
4

You could use WMI to get this information: http://msdn.microsoft.com/en-us/library/aa394084(v=VS.85).aspx

This information is also available in the registry (if WMI isn't to your liking): HKLM/HARDWARE/DESCRIPTION/System/CentralProcessor

NOTE: Registry keys and locations may change. The WMI API is designed as a more stable source for this kind of information.

Stuart Thompson
  • 1,839
  • 2
  • 15
  • 17
4

RAM - GetPhysicallyInstalledSystemMemory (GlobalMemoryStatusEx on earlier versions)

CPU - GetSystemInfo (not in the desired friendly form, I'm afraid). There is a very extensive discussion of more detailed CPU info retrieval here.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140