Click here to Skip to main content
15,881,600 members
Articles / Programming Languages / C++
Article

System Information Utility

Rate me:
Please Sign up or sign in to vote.
4.95/5 (12 votes)
17 Apr 2001 500.1K   8.6K   107   126
Utility to extract system information
  • Download demo project - 228 Kb
  • Sample Image - ComputerInfo.jpg

    This project is an attempt to create a utility or tool application that will display all the system information like CPU, OS, Multimedia, etc. The idea behind this application is no different than the one implemented in most of Microsoft’s System Info utility in Office products. But my application takes couple of steps more and displays more info than the available utilities. In this version (V1) of application, following information is displayed.

    • OS Version
    • CPU
    • Memory
    • Mouse
    • Storage
    • Hard Disk
    • Multimedia (Wave Device)
    • OS Protected Files (Win2K, ME & later)
    • Misc (User Info, Machine Name, etc.)

    All these pieces of information have been implemented as separate COM components. The purpose being that these can be utilized as separately as required by any application. I have tried to implement the component as Automation compatible (Dual interfaces) so that these utilities can be used from scripting clients too.

    The extraction of this information is not a rocket science. All the APIs are available in Win32 SDK. It’s just a matter of knowing what API to use where. So I won’t be going into details of implementation. I will try to list all the APIs used in various components and then you can look for more details in online documentation of Platform SDK.

    OS Version

    This component has been implemented in SystemOS project. Following APIs are used to extract this information.

    • GetVersionEx

    If OSVERSIONINFOEX structure is not available then you will have to take help of registry to determine if WinNT installation is Workstation, Server or Domain Controller. This information is available in ProductType key under HKLM\\System\\CurrentControlSet\\Control\\ProductOptions registry entry.

    CPU

    CPU’s approximate speed can be obtained from registry key ~MHz under HKLM\\Hardware\\Description\\System\\CentralProcessor\\0 registry entry. This technique works on OS other than Win95. For rest of the CPU information, GetSystemInfo API can be used.

    Memory

    This component has been implemented in SystemMemory project. You can use GlobalMemoryStatus API to extract the information about system memory.

    Mouse

    This component has been implemented in SystemMouse project. You can use GetSystemMetrics API to see if a mouse is present and if buttons are swapped or not. To get speed of mouse speed you can use

    SystemParametersInfo
    API.

    Storage

    This component has been implemented in SystemStorage project. This extracts information about all the storage devices attached to a system, internal as well as external. You can use following APIs to accomplish the task of extracting the information.

    • GetLogicalDrives
    • GetDriveType
    • GetDiskFreeSpaceEx
    • GetVolumeInformation

    Hard Disk

    This component has been implemented in SystemHDisk project. This component extracts information about hard disk partitions only. This is accomplished by checking if the drive type is of DRIVE_FIXED or not.

    nDriveType = ::GetDriveType (szCurrentDrive);
    if (nDriveType == DRIVE_FIXED)
    {
       .
    }

    Following APIs are used to extract information.

    • GetLogicalDrives
    • GetDriveType
    • CreateFile
    • DeviceIoControl

    Multimedia

    This component has been implemented in SystemMultiMedia project. This component extracts information about any wave output audio device installed on the system. In the next release of this application, wave input and auxiliary input device information will also be added. Following APIs can be used to extract the information.

    • waveOutGetNumDevs
    • waveOutGetDevCaps

    For this project, make sure that you are linking with winmm.lib library and have following headers file included.

    #include <mmsystem.h>
    #include <mmreg.h>

    OS Protected Files

    This component has been implemented in SystemProtectFiles project. The component extracts list of OS files that has been marked as protected. This feature Windows File Protection (WFP) has been introduced with Windows2000. WFP prevents the replacement of essential system files installed as part of Windows 2000. Applications should not overwrite these files because they are used by the system and other applications. Protecting these files prevents application and operating system failures. All Windows-based applications and their installation programs should be aware of WFP. SfcGetNextProtectedFile API can be used to get the list of protected files.

    Locale Information

    To retrieve locale info there is only one API that you will require, GetLocaleInfo. It is the second parameter to this call, LCType, which you need to specify to get the specific piece of information you want. There are about 100 different values you can specify for this information. For more information on all of them, check the Platform SDK documentation for this API. E.g. If you want to get the English name of the country which was specified at the time of OS installation, you will use the value LOCALE_SENGCOUNTRY for LCType in GetLocaleInfo call. I will not describe each and every value. I think documentation has done this job pretty well. For implementation look in the GetInformation function call of CLocaleInformation class in SystemLocale project.

    Misc

    This component has been implemented in SystemMisc project. This component extracts information like logged in User Name, Machine Name, Local Language, etc. Following APIs can be used to get this information.

    • GetComputerName
    • GetUserName
    • GetSystemDefaultLangID

    How To Use

    Since all these components are COM objects, so make sure that they are all registered. And then you can make use of the standard CoCreateInstance API to create these objects and use their methods and properties. E.g.

    hr = CoCreateInstance (CLSID_OSInformation,
                           0,
                           CLSCTX_INPROC_SERVER,
                           IID_IOSInformation,
                           (void **) &m_pOSInfo
                           );
    if (FAILED (hr)) {
            return E_NOINTERFACE;
    }

    Project Compilation

    This whole application is divided into 12 projects. Initially it was compiled using VC5/6. The project included with this article is for Visual Studio.NET. You will see a lot of warnings about data loss thrown by compiler. The reason is that I have enables the option (/Wp64) for detecting 64 bit portability issues. I am working on resolving these issues so that application is compatible when Win64 is finally released.

    For VC6, open the SystemApplication.dsw file in the SystemApplication folder. And for VS.Net, open the SystemApplication.sln file. The appropriate projects files, DSP (VC6) and VCPROJ (VC7) will automatically get loaded.

    If you need the workspace/projects for VC6, feel free to send me an email. I will send you the DSPs. I am upgrading this application to add more features like BIOS, Video, Modem, Network, etc.

    History

    8 March 2001 - updated source files.

    18 April 2001 - updated source files.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Questionwhy do you wrap these DLL into COM? Pin
    Southmountain4-Sep-20 8:45
    Southmountain4-Sep-20 8:45 
    QuestionPlease send me VC6 Workspace/Projects. Pin
    kimdonghyun777712-May-14 19:57
    kimdonghyun777712-May-14 19:57 
    Generalfor help Pin
    baihe.5915-Jul-10 23:41
    baihe.5915-Jul-10 23:41 
    QuestionAbout SystemInfo Pin
    Mahashan10-Feb-09 1:57
    Mahashan10-Feb-09 1:57 
    Generalcompilation error on VC++ 6.0 Pin
    ranjan5420-Nov-07 20:35
    ranjan5420-Nov-07 20:35 
    Questioncan't open in visual studio 2005 Pin
    sivart6316-Aug-07 19:15
    sivart6316-Aug-07 19:15 
    Generalhelp Pin
    yifeisunny18-Apr-07 21:36
    yifeisunny18-Apr-07 21:36 
    Generalfor you Pin
    samzhang1234527-Mar-07 16:59
    samzhang1234527-Mar-07 16:59 
    QuestionReported Total Memory is incorrect Pin
    rbrunton30-Jan-07 14:36
    rbrunton30-Jan-07 14:36 
    Generalinclude\atl\atlcom.h(2909) : error C2899: typename cannot be used outside a template declaration Pin
    Javali25-Jul-06 2:33
    Javali25-Jul-06 2:33 
    QuestionProtected Files in Vista Pin
    JLINK19-Jul-06 3:43
    JLINK19-Jul-06 3:43 
    QuestionRe: Protected Files in Vista Pin
    greglambert1-Nov-06 0:41
    greglambert1-Nov-06 0:41 
    AnswerRe: Protected Files in Vista Pin
    JLINK1-Nov-06 3:59
    JLINK1-Nov-06 3:59 
    QuestionDevice information DLL Pin
    Satya_wolverine30-Apr-06 17:57
    Satya_wolverine30-Apr-06 17:57 
    GeneralRetrieving Company/Organization Name Pin
    Franc19576-Apr-06 3:44
    Franc19576-Apr-06 3:44 
    GeneralGetsystemInfo Pin
    moudii2-Mar-06 22:52
    moudii2-Mar-06 22:52 
    GeneralSystem information Pin
    ramalingom4-Jan-06 1:05
    ramalingom4-Jan-06 1:05 
    GeneralRe: System information Pin
    Naveen K Kohli5-Jan-06 1:25
    Naveen K Kohli5-Jan-06 1:25 
    GeneralCompilation Error - fail to find a help file hlp\SystemApplication.hpj Pin
    Yoo, Seok19-Dec-05 1:44
    Yoo, Seok19-Dec-05 1:44 
    GeneralRe: Compilation Error - fail to find a help file hlp\SystemApplication.hpj Pin
    Naveen K Kohli5-Jan-06 1:23
    Naveen K Kohli5-Jan-06 1:23 
    Generalget user name of remote computer. Pin
    Tailana13-Jun-05 21:57
    Tailana13-Jun-05 21:57 
    QuestionHow to remotely detect OS version Pin
    Girish60121-May-05 0:12
    Girish60121-May-05 0:12 
    AnswerRe: How to remotely detect OS version Pin
    Naveen K Kohli22-May-05 2:21
    Naveen K Kohli22-May-05 2:21 
    GeneralVC6 DSPs Pin
    asv7-Mar-05 19:45
    asv7-Mar-05 19:45 
    GeneralRe: VC6 DSPs Pin
    Naveen K Kohli22-May-05 2:21
    Naveen K Kohli22-May-05 2:21 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.