views:

214

answers:

2

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++?

+1  A: 

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.

John Feminella
thanks, that is my last choice if i can't implement it with c++ code
A: 

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

MSalters
From the docs "... a directory on another volume (for example, Y:\MountX). The string must end with a trailing backslash ('\')." -- thats a great *bad* example.
Ruddy
Yeah, luckily that example is irrelevant in this case.
MSalters