开发者

Programmatically assign new letter to existing drive with 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++?


SetVolumeMountPoint(L"X:\", volumeName.c_str())


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜