Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

about system

Posted on 1998-10-26
1
Medium Priority
?
226 Views
Last Modified: 2013-11-20
now i use visual c++ 5. I would like to know how i get information system
 such as ( how many drive in computer , name of computer,...).
i will use that information for my application.
please advise me
thank you
0
Comment
Question by:eakkung
[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
1 Comment
 
LVL 3

Accepted Solution

by:
stefanr earned 200 total points
ID: 1323885
SYSTEM_INFO SystemInfo = { 0 };
::GetSystemInfo(&SystemInfo);

//-------x-------

MEMORYSTATUS MemoryStatus = { 0 };
MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
::GlobalMemoryStatus(&MemoryStatus);

//-------x-------

CString strComputerName;
::GetComputerName(strComputerName.GetBuffer(MAX_COMPUTERNAME_LENGTH+1), MAX_COMPUTERNAME_LENGTH+1);
strComputerName.ReleaseBuffer();

//-------x--------

struct PHYDRIVEINFO
{
   CString m_sDrive;
   DISK_GEOMETRY m_DiskGeometry;
   CByteArray m_arrDriveLayout;

   PHYDRIVEINFO() { ::ZeroMemory(&m_DiskGeometry, sizeof(DISK_GEOMETRY)); }
   PHYDRIVEINFO(PHYDRIVEINFO& obj) { ::ZeroMemory(&m_DiskGeometry, sizeof(DISK_GEOMETRY)); }
   PHYDRIVEINFO& operator=(PHYDRIVEINFO& obj) { return *this; }
   PHYDRIVEINFO& operator=(LPCTSTR lpszDrive) { m_sDrive = lpszDrive; return *this; }
};

CArray<PHYDRIVEINFO, LPCTSTR> arrPhysicalDrives;

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 = arrPhysicalDrives.Add(sFileName);
      PHYDRIVEINFO& rPhyDriveInfo = 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.arrDriveLayout.SetSize(sizeof(DRIVE_LAYOUT_INFORMATION) + cPartns*sizeof(PARTITION_INFORMATION));
         ::ZeroMemory(rPhyDriveInfo.arrDriveLayout.GetData(), rPhyDriveInfo.arrDriveLayout.GetSize());
         if (::DeviceIoControl(hFile, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, rPhyDriveInfo.arrDriveLayout.GetData(), rPhyDriveInfo.arrDriveLayout.GetSize(), &dwBytesReturned, NULL))
            break;
         else if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
         {
            rPhyDriveInfo.arrDriveLayout.RemoveAll();
            break;
         }
         cPartns += 4;
      }

      ::CloseHandle(hFile);
   }
}

//-------x--------

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;

   LOGDRIVEINFO()
   {
      m_bInfoValid = FALSE;
      m_dwVolumeSerialNumber = 0;
      m_dwMaxNameLength = 0;
      m_dwFileSystemFlags = 0;
      m_nDriveType = 0;
      m_nSectorsPerCluster = 0;
      m_nBytesPerSector = 0;
      m_nFreeClusters = 0;
      m_nClusters = 0;
   }
   LOGDRIVEINFO(LOGDRIVEINFO& obj)
   {
      m_bInfoValid = FALSE;
      m_dwVolumeSerialNumber = 0;
      m_dwMaxNameLength = 0;
      m_dwFileSystemFlags = 0;
      m_nDriveType = 0;
      m_nSectorsPerCluster = 0;
      m_nBytesPerSector = 0;
      m_nFreeClusters = 0;
      m_nClusters = 0;
      operator=(obj);
   }
   LOGDRIVEINFO& operator=(LOGDRIVEINFO& obj) { m_sDrive = obj.m_sDrive; return *this; }
   LOGDRIVEINFO& operator=(LPCTSTR lpszDrive) { m_sDrive = lpszDrive; return *this; }
};

CArray<LOGDRIVEINFO, LPCTSTR> arrLogicalDrives;

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 = arrLogicalDrives.Add(szLogicalDrive);
   arrLogicalDrives[nIndex].m_bInfoValid = ::GetVolumeInformation(lpsz,
                             arrLogicalDrives[nIndex].m_sVolumeName.GetBuffer(_MAX_PATH), _MAX_PATH,
                             &arrLogicalDrives[nIndex].m_dwVolumeSerialNumber,
                             &arrLogicalDrives[nIndex].m_dwMaxNameLength,
                             &arrLogicalDrives[nIndex].m_dwFileSystemFlags,
                             arrLogicalDrives[nIndex].m_sFileSystemName.GetBuffer(_MAX_PATH), _MAX_PATH);
      arrLogicalDrives[nIndex].m_sVolumeName.ReleaseBuffer();
      arrLogicalDrives[nIndex].m_sFileSystemName.ReleaseBuffer();
   arrLogicalDrives[nIndex].m_nDriveType = ::GetDriveType(lpsz);
   if (arrLogicalDrives[nIndex].m_nDriveType == DRIVE_FIXED || arrLogicalDrives[nIndex].m_nDriveType == DRIVE_CDROM || arrLogicalDrives[nIndex].m_nDriveType == DRIVE_RAMDISK)
   {
      ::GetDiskFreeSpace(lpsz, &arrLogicalDrives[nIndex].m_nSectorsPerCluster, &arrLogicalDrives[nIndex].m_nBytesPerSector,
                                  &arrLogicalDrives[nIndex].m_nFreeClusters, &arrLogicalDrives[nIndex].m_nClusters);
   }
}
delete[] lpszzLogicalDrives;
lpszzLogicalDrives = NULL;

This is taken from an actual application, modified slightly for this informational purpose.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

730 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