I want to change a drive letter. For example, I can use diskpart to assign a new letter to a drive (a USB disk or a new hard disk).
How can I implement it in C/C++?
I want to change a drive letter. For example, I can use diskpart to assign a new letter to a drive (a USB disk or a new hard disk).
How can I implement it in C/C++?
A trivial and easy way to do this would be to just shell out to diskpart
:
int main () {
int i = system("diskpart ..."); // Add args here.
cout << "command exited with code: " << i;
// ...
}
It has an /s
parameter that you can use to supply a script to run inside diskpart
, so you can simply write a text file out with the relevant subcommands and pass that into diskpart
with your system(...)
call.