开发者

Programmatically assign new letter to existing drive with C++

开发者 https://www.devze.com 2022-12-17 09:50 出处:网络
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).

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

精彩评论

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

关注公众号