MFC-Independent class for the easy determination of system information

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.





Click here for larger image

Environment: VC++, WIN32 x86

I have seen MANY people ask for ways to determine different types of system information. Some people want to know the OS version; some want to know memory information; others want to know detailed information about the processor. All of this information, and more, is easily available with the SysInfo class.

There have been other classes in the past that one could use. SysInfo differs from these classes in a few ways:

  1. The SysInfo client is able to get exactly what he/she desires. No more sifting through long, text strings.
  2. The SysInfo class provides full source-code! Yes, if you don’t like what I did, just modify it, or better yet, derive your own class.
  3. The SysInfo class is MFC-independent. This isn’t an issue for a lot of CodeGuru readers, but there are some non-MFCers out there and this class should be easily available to them too … without a lot of editing.
  4. The default project comes with static and dynamic link options. If you want everything bundled in your executable, that’s fine by me!

Of course, everything isn’t perfect with this class. Future enhancements include [but are not limited to]:

  1. IE and/or Windows Media player versions
  2. Comctl32.dll version
  3. Display information
  4. Directx information
  5. Printer information
  6. decent hardware detection

Known “issues” with SysInfo:

  1. The “algorithm” for determining speed is very rudimentary and should be improved upon.
  2. The conversion from bytes to MB [and bytes to GB] is a little off for larger drives.

It’s fairly close though, so I left it alone.

Here’s an example of how easy it is to use SysInfo.

#include “SysInfo.h”

#include
#include

using namespace std;

void main(int argc, char* argv[])
{
SysInfo sysInfo;
cout << “———————” << endl;
cout << “PROCESSOR INFORMATION” << endl;
cout << “———————” << endl;
cout << “CPU String: ” << sysInfo.getCpuIdentification()
<< endl;
cout << “CPU Speed: ” << sysInfo.getCpuSpeed()
<< endl;
cout << “Number of CPUs: ” << sysInfo.getNumProcessors()
<< endl;
cout << “Family: ” << sysInfo.getCpuFamily()
<< endl;
cout << “Model: ” << sysInfo.getCpuModel()
<< endl;
cout << “Stepping: ” << sysInfo.getCpuStepping()
<< endl;

system(“pause”);
system(“cls”);

cout << “——————” << endl;
cout << “PROCESSOR FEATURES” << endl;
cout << “——————” << endl;
cout << “FPU: ” << sysInfo.getFeature(FPU_FLAG)
<< ” ”
<< “CMOV: ” << sysInfo.getFeature(CMOV_FLAG) << endl;
cout << “VME: ” << sysInfo.getFeature(VME_FLAG)
<< ” ”
<< “PAT: ” << sysInfo.getFeature(PAT_FLAG) << endl;
cout << “DE: ” << sysInfo.getFeature(DE_FLAG)
<< ” ”
<< “PSE36: ” << sysInfo.getFeature(PSE36_FLAG) << endl;
cout << “PSE: ” << sysInfo.getFeature(PSE_FLAG)
<< ” ”
<< “PSNUM: ” << sysInfo.getFeature(PSNUM_FLAG) << endl;
cout << “TSC: ” << sysInfo.getFeature(TSC_FLAG)
<< ” ”
<< “CLFLUSH: ” << sysInfo.getFeature(CLFLUSH_FLAG)
<< endl;
cout << “MSR: ” << sysInfo.getFeature(MSR_FLAG)
<< ” ”
<< “DTS: ” << sysInfo.getFeature(DTS_FLAG) << endl;
cout << “PAE: ” << sysInfo.getFeature(PAE_FLAG)
<< ” ”
<< “ACPI: ” << sysInfo.getFeature(ACPI_FLAG) << endl;
cout << “MCE: ” << sysInfo.getFeature(MCE_FLAG)
<< ” ”
<< “MMX: ” << sysInfo.getFeature(MMX_FLAG) << endl;
cout << “CX8: ” << sysInfo.getFeature(CX8_FLAG)
<< ” ”
<< “FXSR: ” << sysInfo.getFeature(FXSR_FLAG) << endl;
cout << “APIC: ” << sysInfo.getFeature(APIC_FLAG)
<< ” ”
<< “SSE: ” << sysInfo.getFeature(SSE_FLAG) << endl;
cout << “SEP: ” << sysInfo.getFeature(SEP_FLAG)
<< ” ”
<< “SSE2: ” << sysInfo.getFeature(SSE2_FLAG) << endl;
cout << “MTRR: ” << sysInfo.getFeature(MTRR_FLAG)
<< ” ”
<< “SS: ” << sysInfo.getFeature(SS_FLAG) << endl;
cout << “PGE: ” << sysInfo.getFeature(PGE_FLAG)
<< ” ”
<< “TM: ” << sysInfo.getFeature(TM_FLAG) << endl;
cout << “MCA: ” << sysInfo.getFeature(MCA_FLAG) << endl;
cout << “3dNow!: ” << sysInfo.getExtFeature(HAS3DNOW_FLAG)
<< ” ”
<< “3dNow!Ex:” << sysInfo.getExtFeature(EXT3DNOW_FLAG)
<< endl;
cout << “SSE MMX: ” << sysInfo.getExtFeature(SSEMMX_FLAG)
<< endl;

system(“pause”);
system(“cls”);

cout << “————–” << endl;
cout << “OS INFORMATION” << endl;
cout << “————–” << endl;
cout << “OS: ” << sysInfo.getOSDescription() << endl;
cout << endl;
cout << “——————” << endl;
cout << “MEMORY INFORMATION” << endl;
cout << “——————” << endl;
cout << “Total: ” << sysInfo.getTotalRam() << endl;
cout << “Available: ” << sysInfo.getAvailRam() << endl;
cout << “Total Page: ” << sysInfo.getTotalPageFile() << endl;
cout << “Avail Page: ” << sysInfo.getAvailPageFile() << endl;
cout << “Total Virtual: ” << sysInfo.getTotalVirtual() << endl;
cout << “Avail Virtual: ” << sysInfo.getAvailVirtual() << endl;

system(“pause”);
system(“cls”);

cout << “——————” << endl;
cout << “SOCKET INFORMATION” << endl;
cout << “——————” << endl;
cout << “Version: ” << sysInfo.getSocketVersion() << endl;
cout << “Highest Ver: ” << sysInfo.getHighestSocketVersion()
<< endl;
cout << “Description: ” << sysInfo.getSocketDescription()
<< endl;
cout << “System Status: ” << sysInfo.getSocketSystemStatus()
<< endl;
cout << “Max: ” << sysInfo.getSocketMax() << endl;
cout << “IP Address: ” << sysInfo.getIPAddress() << endl;
cout << “Domain Name: ” << sysInfo.getDomainName() << endl;
cout << “UDP Max: ” << sysInfo.getSocketUdpMax() << endl;
cout << endl;

cout << “———————-” << endl;
cout << “HARD DRIVE INFORMATION” << endl;
cout << “———————-” << endl;
vector const* pvDriveStats = sysInfo.getDriveStats();
vector::const_iterator i;
for (i = pvDriveStats->begin(); i != pvDriveStats->end(); i++)
{
cout << “Name: ” << i->getName() << ” Type: ” << i->getType()
<< ” Total: ” << i->getTotalSpace() << ” Free: ”
<< i->getFreeSpace() << endl;
}

system(“pause”);
}

Downloads

Download demo project – 57 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read