+ Reply to Thread
Results 1 to 2 of 2

Thread: Get list of all the drives under windows using C/C++

  1. #1

    Get list of all the drives under windows using C/C++

    How can I enumerate all the hard disk drivers on a machine using WIN32/MFC APIs? I want to get the list of all the driver letters. Only hard disk drivers no CD ROM or etc...
    Please advice.

  2. #2
    You should use GetLogicalDriveStrings WIN32 API to get the disk drive letters.

    Example:
    Code:
    void GetHardDiskDrivesNames(CArray<CString, CString> &strIPAddresses)
    {
    	DWORD dwBufferSize = GetLogicalDriveStrings(0, NULL) ;
    	char* pDrives = (char *) malloc(dwBufferSize + 1) ;
    	char* pDrivesToDelete = pDrives ;
        if (pDrives != NULL)
        {
    		GetLogicalDriveStrings(dwBufferSize, pDrives) ;
    		while (*pDrives)
    		{
    			UINT nDriveType = GetDriveType(pDrives);
    			
    			if (DRIVE_FIXED == nDriveType)
    			{
    				strIPAddresses.Add(pDrives) ;
    			}
    			pDrives += lstrlen(pDrives) + 1;
    		}
    
    		free(pDrivesToDelete) ;
    		pDrivesToDelete = NULL ;
    	}
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts