简体   繁体   English

以编程方式使用C ++为现有驱动器分配新字母

[英]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). 例如,我可以使用diskpart为驱动器(USB磁盘或新硬盘)分配一个新字母。

How can I implement it in C/C++? 如何在C / C ++中实现它?

A trivial and easy way to do this would be to just shell out to diskpart : 执行此操作的一个简单而容易的方法是将shell发送到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. 它有一个/s参数,可用于提供在diskpart内运行的脚本,因此您只需使用相关子命令编写一个文本文件,并通过system(...)调用将其传递给diskpart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM