I do not know about WMI, but you can change the drive letter using winapi, here is an example that I ported (you just need the part) to C #
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetVolumeNameForVolumeMountPoint(string
lpszVolumeMountPoint, [Out] StringBuilder lpszVolumeName,
uint cchBufferLength);
[DllImport("kernel32.dll")]
static extern bool DeleteVolumeMountPoint(string lpszVolumeMountPoint);
[DllImport("kernel32.dll")]
static extern bool SetVolumeMountPoint(string lpszVolumeMountPoint,
string lpszVolumeName);
const int MAX_PATH = 260;
private void ChangeDriveLetter()
{
StringBuilder volume = new StringBuilder(MAX_PATH);
if (!GetVolumeNameForVolumeMountPoint(@"D:\", volume, (uint)MAX_PATH))
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
if (!DeleteVolumeMountPoint(@"D:\"))
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
if (!SetVolumeMountPoint(@"Z:\", volume.ToString()))
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
Be careful when running this code, you must remove the mount point of the drive before assigning a new letter, which can lead to problems with the source code:
/*****************************************************************
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
This program will change drive letter assignments, and the
changes persist through reboots. Do not remove drive letters
of your hard disks if you do not have this program on floppy
disk or you might not be able to access your hard disks again!
*****************************************************************/
source
share