MFC Class "System Information"

Monday Dec 23rd 2002 by Alexey Kazakovsky
Share:

Get various items of system information, such as the OS version (for example, Windows 2000 Terminal Server or Windows XP Home Edition), the CPU type, the amount of physical memory and memory usage, the version of IE, the version of ADO, the network interface (NIC) list with the IP addresses, and much more.



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
Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved