MFC-Independent class for the easy determination of system information



Click here for larger image



Click here for larger image



Click here for larger image



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


Comments

  • System bios info

    Posted by Legacy on 02/25/2004 12:00am

    Originally posted by: chetan

    How can I interact with system bios and hardware or get bios information using win32 API's with MFC
    
    I dont want to use API's related to registry editing.

    Reply
  • Dll is not working with c based program

    Posted by Legacy on 12/10/2003 12:00am

    Originally posted by: Priya

    Hi Paul,
    

    I got you beautiful program.
    I have some Querys, Plese try to solve this for me.
    Ref: SysInfo source code:

    1. Can I use this code in my program

    2. I changed SYSINFO_EXPORTS in settings to create a dll but it is not working when I am using it in a c style program.

    (dllexport) is exporting function but with some different name (i.e ?getMMIsInstalled@SysInfo@@QBE_NXZ instade of SysInfo.getMMIsInstalled) and when creating a .def file I dont know where to put extern "C" in the program because after putting this statement it only creates the dll but no function in it to view in depends.Plase help me in solving this.

    Thanks for your code again.

    Regars,
    Priya

    Reply
  • SysInfo Resolution and Multimonitor support

    Posted by Legacy on 12/02/2003 12:00am

    Originally posted by: Lutz Dornbusch

    Hi there !
    I just added support for DisplayInfo. It will give for each Monitor the MonitorHandle, HDC, Xres, Yres, bitplanes, and the Virtual Screencoords. It is running on all windows Versions down to Win95A(which do not even have MultiMonitor support)
    Paul Wendt: Are you interested in this code? I have seen, you have your own DisplayInfo-class in your code, but it is commented out. I only looked briefly over the code and it examines other aspects of display(more driver specific, I think..)
    Anyway thanx for this cool tool!
    Greetings,
    Lutz

    • how many monitors are attatched with a syatem

      Posted by atif_ilm on 06/21/2004 02:29am

      I am looking for some piece of code which could telll me , how many monitors are attatched with a syatem , means detecting of multimonitor support. so can anybody help me.

      Reply
    Reply
  • Original Language of OS .?

    Posted by Legacy on 11/25/2003 12:00am

    Originally posted by: Dillip

    Hi.,
    How to determine the Original Language(no Locale) of the Operating System .?
    Thanks in Advance!

    Cheers,
    DILLIP.

    Reply
  • How about the platform with multiple CPUs?

    Posted by Legacy on 10/15/2003 12:00am

    Originally posted by: Welinn

    Thanks, have a question.
    Some server systems have dual or more CPUs. How could I get all the information (ID, speed...) of bundled CPUs?

    Reply
  • Can it work in dos?

    Posted by Legacy on 10/07/2003 12:00am

    Originally posted by: Joe

    What do I need to do in order to get this or any other c++ program for that matter to run in DOS?

    Reply
  • Very Gooooood?~!

    Posted by Legacy on 10/06/2003 12:00am

    Originally posted by: Thank u~!?

    Good I find IT!~~!

    Reply
  • System Info

    Posted by Legacy on 09/29/2003 12:00am

    Originally posted by: M. kashif Iqbal

    hello 
    
    

    I want to get the size of hard disk, size of RAM, CPU speed, and the modem info for my final project of MCS. Plz do help me.

    Thanks

    Reply
  • Sysinfo

    Posted by Legacy on 09/17/2003 12:00am

    Originally posted by: sdaga

    how to access std::string variables or get the value of
    sysInfo.getTotalRam() as an string?

    Reply
  • Request: CPU Usage

    Posted by Legacy on 09/09/2003 12:00am

    Originally posted by: Daniel Berger

    I would love to see some CPU usage information added. Thanks for a very handy bit of software btw!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds