A trivial and easy way to do this is to simply fork out for diskpart :
int main () { int i = system("diskpart ...");
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(...) .
source share