How to get the drive letter that the system already exists under Windows

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.