Solved

Question on system info

Posted on 1998-11-10
5
300 Views
Last Modified: 2013-11-20
Hi there,
          How can I use GetSystemInfo(); in MFC to get the system info and display it using MessageBox();

Any help offered is very much appreciated!
0
Comment
Question by:justinng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
stefanr earned 100 total points
ID: 1324457
This is taken directly from actual code, slightly modified:

   SYSTEM_INFO m_SystemInfo;

   . . .

   ::GetSystemInfo(&m_SystemInfo);

   CString s;

   switch (m_SystemInfo.wProcessorArchitecture)
   {
   case PROCESSOR_ARCHITECTURE_INTEL:
      s = _T("Intel");
      switch (m_SystemInfo.wProcessorLevel)
      {
      case 0:
      case 1:
      case 2:
         break;
      case 3:
         s += _T(" 80386");
      case 4:
         s += _T(" 80486");
         break;
      case 5:
         s += _T(" Pentium");
         break;
      default:
         {
            CString sTemp;
            sTemp.Format(_T(" x86 Family %hu"), m_SystemInfo.wProcessorLevel);
            s += sTemp;
         }
         break;
      }
      if (m_SystemInfo.wProcessorLevel == 3 || m_SystemInfo.wProcessorLevel == 4)
      {
         if (((m_SystemInfo.wProcessorRevision >> 8) & 0xFF) == 0xFF)
         {
            CString sTemp;
            sTemp.Format(_T("-%02X"), UINT(m_SystemInfo.wProcessorRevision & 0xFF));
            s += sTemp;
         }
         else
         {
            CString sTemp;
            sTemp.Format(_T("-%c%u"), TCHAR(_T('A') + ((m_SystemInfo.wProcessorRevision >> 8) & 0xFF)), UINT(m_SystemInfo.wProcessorRevision & 0xFF));
            s += sTemp;
         }
      }
      else if (m_SystemInfo.wProcessorLevel >= 5)
      {
         CString sTemp;
         sTemp.Format(_T(" Model %u Stepping %u"), UINT((m_SystemInfo.wProcessorRevision >> 8) & 0xFF), UINT(m_SystemInfo.wProcessorRevision & 0xFF));
         s += sTemp;
      }
      break;
   case PROCESSOR_ARCHITECTURE_MIPS:
      s = _T("Processor Architecture: PROCESSOR_ARCHITECTURE_MIPS");
      break;
   case PROCESSOR_ARCHITECTURE_ALPHA:
      s = _T("Processor Architecture: PROCESSOR_ARCHITECTURE_ALPHA");
      break;
   case PROCESSOR_ARCHITECTURE_PPC:
      s = _T("Processor Architecture: PROCESSOR_ARCHITECTURE_PPC");
      break;
   case PROCESSOR_ARCHITECTURE_UNKNOWN:
      s = _T("Processor Architecture: PROCESSOR_ARCHITECTURE_UNKNOWN");
      break;
   default:
      break;
   }

   ::MessageBox(hWnd, s, _T("SYSTEM_INFO"), MB_OK);

Just replace the code for CString with your own string handling.
0
 

Author Comment

by:justinng
ID: 1324458
Thanks stefanr! Is it also possible to get informations like no. of drives, diskspace etc??

0
 
LVL 3

Expert Comment

by:stefanr
ID: 1324459
Yes, you can call CreateFile on the device \\.\PHYSICALDRIVEn, where n is the number 0 and up, to obtain physical characteristics of the hard disks using the DeviceIoControl call. Indirectly you get the number of physical disks by counting the number of times CreateFile succeeds. Don't forget to call CloseHandle when done with a disk, though.
You enumerates the names of the logical drives by calling GetLogicalDriveStrings, where you get a double-zero terminated string of zero-terminated substrings, or GetLogicalDrives to retrieve a bitmask of at most 32 logical drives.
You retrieves the free space on a logical drive with the GetDiskFreeSpaceEx function.
And if you're working with NT you can use the performance data to retrieve all kind of statistics (dynamic data) about the system.
0
 

Author Comment

by:justinng
ID: 1324460
Is there any code segments to illustrate? thanks! I'm new to MFC programming....
0
 
LVL 3

Expert Comment

by:stefanr
ID: 1324461
This is copied directly from actual code:

   struct LOGDRIVEINFO
   {
      BOOL m_bInfoValid;
      CString m_sDrive;
      CString m_sVolumeName;
      DWORD m_dwVolumeSerialNumber;
      DWORD m_dwMaxNameLength;
      DWORD m_dwFileSystemFlags;
      CString m_sFileSystemName;
      UINT m_nDriveType;
      unsigned long m_nSectorsPerCluster;
      unsigned long m_nBytesPerSector;
      unsigned long m_nFreeClusters;
      unsigned long m_nClusters;
      ...
   };

   CArray<LOGDRIVEINFO, LPCTSTR> m_arrLogicalDrives;

----

   const int MAXPHYDRIVE = 16;

   const CString sFileNamePrefix = _T("\\\\.\\");
   CString sFileName;
   CString sFilePath;
   HANDLE hFile = INVALID_HANDLE_VALUE;
   for (int i = 0; i < MAXPHYDRIVE; i++)
   {
      sFileName.Format(_T("PHYSICALDRIVE%d"), i);
      sFilePath = sFileNamePrefix + sFileName;
      hFile = ::CreateFile(sFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      if (hFile != INVALID_HANDLE_VALUE)
      {
         int nIndex = m_arrPhysicalDrives.Add(sFileName);
         PHYDRIVEINFO& rPhyDriveInfo = m_arrPhysicalDrives.ElementAt(nIndex);
         DWORD dwBytesReturned = 0;
         ::DeviceIoControl(hFile, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &rPhyDriveInfo.m_DiskGeometry, sizeof(DISK_GEOMETRY), &dwBytesReturned, NULL);

         int cPartns = 4;
         while (TRUE)
         {
            rPhyDriveInfo.m_arrDriveLayout.SetSize(sizeof(DRIVE_LAYOUT_INFORMATION) + cPartns*sizeof(PARTITION_INFORMATION));
            ::ZeroMemory(rPhyDriveInfo.m_arrDriveLayout.GetData(), rPhyDriveInfo.m_arrDriveLayout.GetSize());
            if (::DeviceIoControl(hFile, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, rPhyDriveInfo.m_arrDriveLayout.GetData(), rPhyDriveInfo.m_arrDriveLayout.GetSize(), &dwBytesReturned, NULL))
               break;
            else if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
            {
               rPhyDriveInfo.m_arrDriveLayout.RemoveAll();
               break;
            }
            cPartns += 4;
         }

         ::CloseHandle(hFile);
      }
   }

----

   const int LOGDRIVEBUFSIZE = 1024;
   LPTSTR lpszzLogicalDrives = new TCHAR[LOGDRIVEBUFSIZE];
   ::ZeroMemory(lpszzLogicalDrives, LOGDRIVEBUFSIZE * sizeof(TCHAR));
   ::GetLogicalDriveStrings(LOGDRIVEBUFSIZE, lpszzLogicalDrives);

   for (LPTSTR lpsz = lpszzLogicalDrives; *lpsz != 0; lpsz += ::_tcslen(lpsz)+1)
   {
      TCHAR szLogicalDrive[4] = { 0 };
      ::_tcsnccpy(szLogicalDrive, lpsz, ::_tcslen(lpsz)-1);
      int nIndex = m_arrLogicalDrives.Add(szLogicalDrive);
      m_arrLogicalDrives[nIndex].m_bInfoValid = ::GetVolumeInformation(lpsz,
                             m_arrLogicalDrives[nIndex].m_sVolumeName.GetBuffer(_MAX_PATH), _MAX_PATH,
                             &m_arrLogicalDrives[nIndex].m_dwVolumeSerialNumber,
                             &m_arrLogicalDrives[nIndex].m_dwMaxNameLength,
                             &m_arrLogicalDrives[nIndex].m_dwFileSystemFlags,
                             m_arrLogicalDrives[nIndex].m_sFileSystemName.GetBuffer(_MAX_PATH), _MAX_PATH);
      m_arrLogicalDrives[nIndex].m_sVolumeName.ReleaseBuffer();
      m_arrLogicalDrives[nIndex].m_sFileSystemName.ReleaseBuffer();
      m_arrLogicalDrives[nIndex].m_nDriveType = ::GetDriveType(lpsz);
      if (m_arrLogicalDrives[nIndex].m_nDriveType == DRIVE_FIXED || m_arrLogicalDrives[nIndex].m_nDriveType == DRIVE_CDROM || m_arrLogicalDrives[nIndex].m_nDriveType == DRIVE_RAMDISK)
      {
         ::GetDiskFreeSpace(lpsz, &m_arrLogicalDrives[nIndex].m_nSectorsPerCluster, &m_arrLogicalDrives[nIndex].m_nBytesPerSector,
                                  &m_arrLogicalDrives[nIndex].m_nFreeClusters, &m_arrLogicalDrives[nIndex].m_nClusters);
      }
   }
   delete[] lpszzLogicalDrives;
   lpszzLogicalDrives = NULL;

----

   CString sRootPathName;
   for (int i = 0; i <= m_arrLogicalDrives.GetUpperBound(); i++)
   {
      if (m_arrLogicalDrives[i].m_nDriveType == DRIVE_FIXED || m_arrLogicalDrives[i].m_nDriveType == DRIVE_CDROM || m_arrLogicalDrives[i].m_nDriveType == DRIVE_RAMDISK)
      {
         sRootPathName = m_arrLogicalDrives[i].m_sDrive + _T("\\");
         ::GetDiskFreeSpace(sRootPathName, &m_arrLogicalDrives[i].m_nSectorsPerCluster, &m_arrLogicalDrives[i].m_nBytesPerSector,
                                  &m_arrLogicalDrives[i].m_nFreeClusters, &m_arrLogicalDrives[i].m_nClusters);
      }
   }

----

Sorry, but performance data is much too complicated to exemplify. If you want that, you have to search the online documentation (keywords "performance data") and study it from the ground up yourself. You can also look at Performance Data Helper to see if it has something to give.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 101
modThree challenge 4 155
post4 challenge 28 122
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,705
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question