Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question on system info

Posted on 1998-11-10
5
Medium Priority
?
318 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
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
stefanr earned 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

916 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