In the project development, the use of the company's SDK to the system partition, the WINDOWS2003 system under the partition can not be automatically assigned to the new partition of the letter, of course, the system will be restarted after the allocation of the letter, but I do not want it to restart, so my idea is to use the program to automatically assign the new partition drive letter. The allocation letter preparation uses the Assign letter method in the DiskPart command, but the new drive letter cannot conflict with an existing drive letter.
So the question is, how can you get the existing drive letter, including the assigned drive letter for CD/DVD, USB drive, etc.?
#include <iostream>
#include <windows.h>
using namespace Std;
int main ()
{
Char rootpath[10] = {0}, drivetype[21] = {0};
UINT NType;
for (char a = ' a '; a <= ' Z '; a++)
{
sprintf (RootPath, "%c:\\", a);
NType = GetDriveType (RootPath);
if (nType! = drive_no_root_dir)//Drive_no_root_dir: Invalid Path
{
Switch (nType)
{
Case drive_fixed:
strcpy (DriveType, "hdd");
Break
Case Drive_removable:
strcpy (DriveType, "mobile hdd");
Break
Case Drive_cdrom:
strcpy (DriveType, "CD-ROM");
Break
Case Drive_ramdisk:
strcpy (DriveType, "RAM Disk");
Break
Case Drive_remote:
strcpy (DriveType, "Remote Network Drive");
Break
Case Drive_unknown:
Default
strcpy (DriveType, "Unknown disk");
Break
}
cout<<rootpath<< "\ T" <<driveType<<endl;
}
}
return 0;
}
How to get the drive letter that the system already exists under Windows