MFC Class "System Information"



Click here for a larger image.

Environment: VC6/VC7

This CSysInfo class makes it easy to get various system information, such as:

  • OS version (for example, Windows 2000 Terminal Server or Windows XP Home Edition)
  • CPU type
  • Total amount of physical memory and memory usage
  • IE version (very useful for XML-enabled applications)
  • ADO version
  • Does the current user have administrator rights?
  • Network interface (NIC) list with their IP addresses
  • and so on...

Usage

  1. Include SysInfo.cpp, SysInfo.h, MibAccess.cpp, and MibAccess.h in your project.
  2. Create s new CSysInfo class object (for example, m_si) and just invoke CSysInfo::Init().
  3. You will be able to use the member function listed below.

Member Functions

  • Operation system functions:
    • IsWindowsNT()
    • LPCTSTR GetOSType()
    • DWORD GetWinMajor()
    • DWORD GetWinMinor()
    • DWORD GetBuildNumber()
    • DWORD GetServicePack()
  • CPU functions:
    • DWORD GetNumProcessors()
    • DWORD GetCPUSpeed()
    • LPCTSTR GetCPUIdentifier()
    • LPCTSTR GetCPUVendorIdentifier()
    • LPCTSTR GetCPUNameString()
  • Memory functions:
  • Function Description
    DWORD GetProcessMemoryUsage(); Size of the current process
    DWORD GetMemoryLoad() The approximate percentage of total physical memory that is in use
    DWORD64 GetTotalPhys() Total size of physical memory, in bytes
    DWORD64 GetAvailPhys() Size of physical memory available, in bytes
    DWORD64 GetTotalPageFile() Size of the committed memory limit, in bytes
    DWORD64 GetAvailPageFile() Size of available memory to commit, in bytes
    DWORD64 GetTotalVirtual() Total size of the user mode portion of the virtual address space of the calling process, in bytes
    DWORD64 GetAvailVirtual() Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes
  • IE version function:
    • DWORD GetIEMajor()
    • DWORD GetIEMinor()
    • DWORD GetIEBuild()
    • DWORD GetIESomething()
  • ADO version function:
    • DWORD GetADOMajor()
    • DWORD GetADOMinor()
    • DWORD GetADOBuild()
    • DWORD GetADOSomething()
  • Getting NIC list with Iphlpapi.dll (works only under Windows 98+ or Windows 2000+):
    • BOOL IsIphlpapiCompat()—Is your system compatible to use the Iphlpapi interface?
    • int GetAPINumAdapters()—Get the number of network adapters installed
    • DWORD GetAPIAdapterIndex(int i)—Get the internal index of NIC (see MSDN: IP_ADAPTER_INFO structure)
    • LPCSTR GetAPIAdapterName(int i)
    • LPCSTR GetAPIAdapterDescr(int i)
    • int GetAPINumAddresses(int i)—Get the number of IP addresses that belong to the desired adapter
    • LPCSTR GetAPIAdapterIPStr(int i, int indexIP)—index - index of NIC, indexIP - index of IP address
    • LPCSTR GetAPIAdapterMaskStr(int i, int indexIP)
    • BOOL GetAPIAdapterSpeedStatus(int i, DWORD *pdwSpeed, DWORD *pdwStatus)
  • Getting NIC list with MIB (inetmib1.dll—works under Windows 95+ and Windows NT4.0+)
    • SetShowLoopback(BOOL bStatus)—show loopback adapter in the NIC list?
    • int GetMIBNumAdapters()—Get the number of network adapters installed
    • LPCSTR GetMIBAdapterDescr(int i)
    • DWORD GetMIBAdapterIPDword(int i)—Get the IP address of the adapter as a DWORD
    • DWORD GetMIBAdapterMaskDword(int i)—Get the mask of the adapter as a DWORD
    • void GetMIBAdapterIPStr(int i, LPTSTR lpIPStr)—Copy the IP address of the adapter as a string in lpIPStr
    • void GetMIBAdapterMaskStr(int i, LPTSTR lpMaskStr)—Copy the mask of the adapter as a string in lpMaskStr
    • int GetMIBAdapterType(int i) (see sysinfo.h)
    • DWORD GetMIBAdapterSpeed(int i)
    • DWORD GetMIBAdapterOperStatus(int i) (see sysinfo.h)
    • int GetMIBAddresses()—Get the number of IP addresses belonging to this PC
    • int MIBRefreshAddresses()—Refresh the list of IP addresses belonging to this PC (DWORD m_dwMIBIPArray[MAX_IPADDRESSES])
    • DWORD GetMIBIP(int index)—Get the IP from the list of IP addresses
  • Misc functions:
    • BOOL IsUserAdmin()
    • LPCTSTR GetLoginUserName()
    • BOOL GetFileInfo(LPCTSTR lpszFileName, DWORD *v_major, DWORD *v_minor, DWORD *v_build, DWORD *v_something, DWORD *size)—get the version and the size of file
    • BOOL GetSystemFileInfo(LPCTSTR lpszFileName, DWORD *v_major, DWORD *v_minor, DWORD *v_build, DWORD *v_something, DWORD *size)—get the version and the size of file. Look up the file in the Windows system folder (for example, c:\winnt\system32)
    • LPCTSTR GetWorkingDir()—get the folder from which this application has been launched

Downloads

Download demo project - 61KB Kb
Download source - 15KB


Comments

  • Very good article.

    Posted by Ajay Vijay on 02/03/2005 02:37am

    That's really an excellent and complete article for getting system information.

    Reply
  • Can't compile project "MFC Class "System Information"

    Posted by utnqbao on 04/16/2004 03:39am

    I couldn't compile this project because thi project don't include file "iphlpapi.h".Can you help me?

    • Can't compile

      Posted by SW YZ on 04/10/2007 06:00pm

      The compile failed due to can't find iphlphpi.h also. Can anyone help? Thanks.

      Reply
    Reply
  • VERY USEFUL.

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

    Originally posted by: Asha

    Please do mail me the source code to obtain the system details and also about the other nodes in the network by retriving the IP add. of the other nodes from the current machine, if u don't mind.
    This info. was so useful to me but i could'nt view the code.

    I'm down aproject in NMS. PLEASE DO HELP IF U DON'T MIND!!

    Reply
  • fatal error LNK1104: cannot open file "mfc42u.lib"

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

    Originally posted by: Narendra

    I getting the fatal error LNK1104: cannot open file "mfc42u.lib" while builing the project do you have any ideas. What need to be done to fix this.

    Narendra

    • Install UNICODE support

      Posted by Ajay Vijay on 02/03/2005 02:38am

      When you Install Visual Studio, Unicode libraries of MFC are not installed. Lauch the setup program of VC/VS and select the required option.

      Reply
    • change the configuration

      Posted by jayanth_holla on 11/11/2004 10:22pm

      even i had the same problem, while i downloaded the source and built it. it was building in unicode release . just change it to win32 debug in active configuration and build it again, i think it should work jayanth

      Reply
    Reply
  • great, but....

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

    Originally posted by: narada

    Great, but, does it work in any Windows version?

    Thanks,

    Reply
  • Nice, Alexey! Question...

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

    Originally posted by: Brian

    I need to write one utility that performs a version check on I.E. and on Windows and looks up the result in a hash which points to a file name and then runs the filename (with options). I can make that hash in a file,
    and that would be easier to edit. It can be any format though.
    I imagine something like:

    Win31 3.1 "file"
    Win31 3.15 "file"
    Win95 4.1 "file"
    Win95 5.0 "file"
    Win95 5.5 "file"
    Win98 4.1 "file"
    Win98 5.0 "file"
    etc..

    I want to be able to put

    IEpatch.exe /H:hashfile.hsh /D:.\jan02

    in a login script and have all versions of the microsoft patches sitting in .\jan02. The program would perform the tests on the local computer, match them against the list of results in hashfile.hsh and then run the file that matched the results with valid command line options.

    Any thoughts?

    Reply
  • Good Try but .......

    Posted by Legacy on 12/24/2002 12:00am

    Originally posted by: Siva

    Good Try but Compile with error free and provide necess.. header file or provide the .exe file to run.

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

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Live Event Date: November 18, 2014 @ 11:00 a.m. EST As you embrace the hybrid world of on-premise and cloud applications, often accessed via mobile devices, you now have to be concerned that cybercriminals have yet another vehicle to attack your business. In fact, the average cost of cybercrime has increased over 10% in the last year, and this applies to businesses of all sizes. Attend this webinar to hear David Monahan, Security Research Director at EMA, and Dana Epp, recognized security luminary from …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds