Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Ultimate Toolbox System Information Class

0.00/5 (No votes)
25 Aug 2007 1  
The Ultimate Toolbox provides a system info class that can query various aspects of machine and network settings

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\utility\SysInfo1 directory of the sample projects download.

Overview

The COXSysInfo class is an easy way to have an application query a computer for system information. Various system parameters can be examined using this utility class.

This sample program shows most of the functionality of the COXSysInfo class.

Several system parameters are listed, showing the abilities of the class.

Features

  • Can query computer name, user name and current IP address.
  • Can get Windows version, Windows folder, System folder and Temp folder.
  • Can get information about a drive (type and free space available).
  • Can get information about the current display resolution and number of colors.
  • Can get information about the current memory usage.
  • Can get system information about the number of CPUs and their types.

The sample simply creates a member COXSysInfo m_oxSysInfo object (include OXSysInfo.h) then calls a member GetSystemInformation to query various categories of system attributes and populate a tree control:

void CSysInfo1Dlg::GetSystemInformation()
{
    CString    theBuffer ;
    int        xRes, yRes ;
    DWORD    dwValue ;
    CString    theString ;
    HTREEITEM hTypeItem = 0;
    // ***************


    // Windows version


    // ***************


    DWORD    dwPlatform, dwMajor, dwMinor ;
    CString    theVersion ;
    HTREEITEM  after = 0;
    if (m_oxSysInfo.GetWindowsVersion(&dwPlatform, &dwMajor, 
        &dwMinor))
    {
        theBuffer.Format(_T(" WINDOWS "));
        hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
        m_InfoTree.SetItemImage(hTypeItem, 0,1);
        //


        if (dwPlatform == VER_PLATFORM_WIN32s)
            theVersion = _T("Windows 3.1");
        else
            if (dwPlatform == VER_PLATFORM_WIN32_WINDOWS)
            {
                if (dwMajor == 4)
                {
                    switch (dwMinor)
                    {
                    case 0:
                        {
                            theVersion = _T("Windows 95");
                            // if szCSDVersion[1] is C or B, it's OSR2, but 


                            // we're not getting that info back


                        }
                        break;
                    case 10:
                        theVersion = _T("Windows 98");
                        // if szCSDVersion[1] is A, it's SE, but one again, 


                        // we don't get that back


                        break;
                    case 90:
                        theVersion = _T("Windows ME");
                        break;
                    }
                }
                else
                    theVersion = _T("Unknown version");
            }
            else
                if (dwPlatform == VER_PLATFORM_WIN32_NT)
                {
                    if (dwMajor == 5)
                    {
                        switch (dwMinor)
                        {
                        case 2:
                            theVersion=_T("Windows Server 2003");
                            break;
                        case 1:
                            theVersion = _T("Windows XP");
                            break;
                        case 0:
                            theVersion = _T("Windows 2000");
                            break;
                        default:
                            theVersion = _T("Windows Vista");
                        }
                    }
                    else
                        theVersion = _T("Windows NT");
                }
                else
                    theVersion = _T("Unknown");

        theBuffer.Format(_T("Windows Version: %s, %u.%u"), 
            theVersion, dwMajor, dwMinor) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemImage(after, 2,2);
    }
    // **************


    // Processor Type


    // **************


    DWORD    dwProcessorType ;

    if (m_oxSysInfo.GetProcessorType(&dwProcessorType))
    {
        theBuffer.Format(_T(" PROCESSOR ")) ;
        hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
        m_InfoTree.SetItemImage(hTypeItem, 11,11);
        ////


        theBuffer = _T("Processor: ");

        switch(dwProcessorType)
        {
        case PROCESSOR_INTEL_386:
            theBuffer += _T("Intel 386");
            break ;

        case PROCESSOR_INTEL_486:
            theBuffer += _T("Intel 486");
            break ;

        case PROCESSOR_INTEL_PENTIUM:
            theBuffer += _T("Intel Pentium");
            break ;

        case PROCESSOR_MIPSR4000:
            theBuffer += _T("MIPS R4000");
            break ;

        case PROCESSOR_ALPHA21064:
            theBuffer += _T("Alpha 21064");
            break ;

        case PROCESSOR_ALPHA21066:
            theBuffer += _T("Alpha 21066");
            break ;

        case PROCESSOR_ALPHA21164:
            theBuffer += _T("Alpha 21164");
            break ;

        case PROCESSOR_PPC601:
            theBuffer += _T("PowerPC 601");
            break ;

        case PROCESSOR_PPC603:
            theBuffer += _T("PowerPC 603");
            break ;

        case PROCESSOR_PPC604:
            theBuffer += _T("PowerPC 604");
            break ;

        case PROCESSOR_PPC603PLUS:
            theBuffer += _T("PowerPC 603+");
            break ;

        case PROCESSOR_PPC604PLUS:
            theBuffer += _T("PowerPC 604+");
            break ;

        case PROCESSOR_PPC620:
            theBuffer += _T("PowerPC 620");
            break ;

        default:
            theBuffer += _T("UNKNOWN");
            break ;
        }
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    // **************


    // Number of CPUs


    // **************


    int    iNumProcessors ;
    if (m_oxSysInfo.GetNumProcessors(&iNumProcessors))
    {
        theBuffer.Format(_T("Number of CPUs: %d"), iNumProcessors) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    theBuffer.Format(_T(" COMPUTER ")) ;
    hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
    m_InfoTree.SetItemImage(hTypeItem, 6,6);
    //


    // *************


    // Computer name


    // *************


    if (m_oxSysInfo.GetComputerName(&theString))
    {
        theBuffer.Format(_T("Computer Name: %s"), theString) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    // *********


    // User & Domain name


    // *********


    if (m_oxSysInfo.GetUserName(&theString))
    {
        theBuffer.Format(_T("User Name: %s"), theString) ;
        hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
        m_InfoTree.SetItemImage(hTypeItem, 9,9);
    }
    CString sDomain;
    if (m_oxSysInfo.GetUserAndDomainName(&theString, &sDomain))
    {
        theBuffer.Format(_T("User Name: %s"), theString) ;
        hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
        m_InfoTree.SetItemImage(hTypeItem, 9,9);
        theBuffer.Format(_T("Domain Name: %s"), sDomain) ;
        hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
        m_InfoTree.SetItemImage(hTypeItem, 9,9);
    }
    // **********


    // IP Address


    // **********



    CStringArray IPArray;
    if (m_oxSysInfo.GetListIPAddresses(&IPArray))
    {
        for (int j = 0; j < IPArray.GetSize(); j++)
        {
            theBuffer.Format(_T("IP Address(%d): %s"), j, IPArray[j]);
            hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
            m_InfoTree.SetItemImage(hTypeItem, 5,5);
        }
    }
    theBuffer.Format(_T(" DIRECTORIES ")) ;
    hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
    m_InfoTree.SetItemImage(hTypeItem, 8,8);
    //


    // *****************


    // Windows directory


    // *****************


    if (m_oxSysInfo.GetWindowsDir(&theString))
    {
        theBuffer.Format(_T("Windows Directory: %s"), theString) ;
        after = m_InfoTree.InsertItem(theBuffer,hTypeItem );
        m_InfoTree.SetItemImage(after, 6,6);
    }
    // ****************


    // System directory


    // ****************


    if (m_oxSysInfo.GetSystemDir(&theString))
    {
        theBuffer.Format(_T("System Directory: %s"), theString) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemImage(after, 6,6);
    }
    // *******************


    // Temporary directory


    // *******************


    if (m_oxSysInfo.GetTempDir(&theString))
    {
        theBuffer.Format(_T("Temp Directory: %s"), theString) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemImage(after, 6,6);
    }
    // ****************


    // Disk information


    // ****************


    theBuffer.Format(_T(" DISK INFORMATION ")) ;
    hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
    m_InfoTree.SetItemImage(after, 6,6);
    //


    int        i, iDiskType ;
    CString    theFileSysType ;
    CString    theVolName ;
    DWORDLONG    dwTotalSpace, dwFreeSpace;
    DWORD    dwVolSer ;

    for(i=0;i<26;i++)
    {
        if (m_oxSysInfo.GetDriveTypeInfo(i, &theFileSysType, &iDiskType))
        {
            if (m_oxSysInfo.GetDriveVolumeInfo(i, &theVolName, &dwVolSer, 
                &dwTotalSpace, &dwFreeSpace))
            {
                if (iDiskType == DRIVE_FIXED)
                {
                    theBuffer.Format(_T("Drive %c: Fixed Disk"), 
                        i + 65) ;
                    after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                    m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                    //m_InfoTree.SetItemImage(after, 3,3);


                    theBuffer.Format(_T("  Volume Name: %s (%s)"), 
                        theVolName, theFileSysType) ;
                    after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                    m_InfoTree.SetItemImage(after, 3,3);
                    m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                    theBuffer.Format(_T("  Volume Serial: %u"), 
                        dwVolSer) ;
                    after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                    m_InfoTree.SetItemImage(after, 3,3);
                    m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);

                    LPTSTR psBuffer=theBuffer.GetBuffer(256);
                    UTBStr::stprintf(psBuffer, 256, _T(
                        "  Total Space: %I64d "), dwTotalSpace) ;
                    theBuffer.ReleaseBuffer();
                    after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                    m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                    m_InfoTree.SetItemImage(after, 3,3);

                    psBuffer=theBuffer.GetBuffer(256);
                    UTBStr::stprintf(psBuffer, 256,_T(
                        "  Total Space: %I64d "), dwFreeSpace) ;
                    theBuffer.ReleaseBuffer();
                    after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                    m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                    m_InfoTree.SetItemImage(after, 3,3);
                }
                else
                    if (iDiskType == DRIVE_CDROM)
                    {
                        theBuffer.Format(_T("Drive %c: CD-ROM"), 
                           i + 65) ;
                        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);

                        theBuffer.Format(_T(
                            "  Volume Name: %s (%s)"), theVolName, 
                            theFileSysType) ;                            
                        hTypeItem = m_InfoTree.InsertItem(theBuffer, 
                            m_hRootItem);
                        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
                        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                        m_InfoTree.SetItemImage(after, 3,3);
                    }
                    else
                        if (iDiskType == DRIVE_REMOTE)
                        {
                            theBuffer.Format(_T(
                                "Drive %c: Network Disk"), i + 65) ;
                            after = m_InfoTree.InsertItem(theBuffer, 
                                hTypeItem);
                            m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);

                            theBuffer.Format(_T(
                                "  Volume Name: %s (%s)"), 
                                theVolName, theFileSysType) ;
                            after = m_InfoTree.InsertItem(theBuffer, 
                                hTypeItem);
                            m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
                            m_InfoTree.SetItemImage(after, 3,3);
                        }
            }
        }
    }
    theBuffer.Format(_T(" DISPLAY ")) ;
    hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
    //


    // ******************


    // Display resolution


    // ******************


    if (m_oxSysInfo.GetDisplayResolution(&xRes, &yRes))
    {
        theBuffer.Format(_T("Display Resolution: %d x %d"), xRes, 
            yRes) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    // **************


    // Display colors


    // **************


    int        iNumBits ;
    DWORDLONG    dwNumColors;

    if (m_oxSysInfo.GetDisplayNumColors(&dwNumColors, &iNumBits))
    {
        LPTSTR psBuffer=theBuffer.GetBuffer(256);
        UTBStr::stprintf(psBuffer, 256,_T(
            "Current Display Colors: %I64d (%d bits)"), 
            dwNumColors, iNumBits) ;
        theBuffer.ReleaseBuffer();
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    // ******


    // Memory


    // ******


    theBuffer.Format(_T(" MEMORY ")) ;
    hTypeItem = m_InfoTree.InsertItem(theBuffer, m_hRootItem);
    //


    if (m_oxSysInfo.GetTotalPhysicalMemory(&dwValue))
    {
        theBuffer.Format(_T("Total Physical RAM: %u bytes"), 
            dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    if (m_oxSysInfo.GetFreePhysicalMemory(&dwValue))
    {
        theBuffer.Format(_T("Free Physical RAM: %u bytes"), 
            dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    if (m_oxSysInfo.GetTotalPageFile(&dwValue))
    {
        theBuffer.Format(_T("Total Page File: %u bytes"), dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    if (m_oxSysInfo.GetFreePageFile(&dwValue))
    {
        theBuffer.Format(_T("Free Page File: %u bytes"), dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    if (m_oxSysInfo.GetTotalVirtual(&dwValue))
    {
        theBuffer.Format(_T("Total Virtual Memory: %u bytes"), 
            dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, TVI_DATA_FOLDER);
        m_InfoTree.SetItemImage(after, 3,3);
    }
    if (m_oxSysInfo.GetFreeVirtual(&dwValue))
    {
        theBuffer.Format(_T("Free Virtual Memory: %u bytes"), 
            dwValue) ;
        after = m_InfoTree.InsertItem(theBuffer, hTypeItem);
        m_InfoTree.SetItemData(after, (DWORD)3);
        m_InfoTree.SetItemImage(after, 3,3);
    }
}

A complete class reference for the COXSysInfo class is available in the compiled HTML help documentation.

History

Initial CodeProject release August 2007.

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