Programmatically Assign a New Letter to an Existing C ++ Drive

I want to change the drive letter. For example, I can use diskpart to assign a new letter to the disk (USB drive or new hard drive).

How can I implement it in C / C ++?

+4
source share
2 answers

A trivial and easy way to do this is to simply fork out for diskpart :

 int main () { int i = system("diskpart ..."); // Add args here. cout << "command exited with code: " << i; // ... } 

It has the /s option, which can be used to supply a script to run inside diskpart , so you can simply write a text file with the appropriate subcommands and pass it to diskpart using system(...) .

+1
source

Source: https://habr.com/ru/post/1298959/


All Articles