Geoff

Geoff

  • NA
  • 6
  • 0

Changing the drive letter of a volume

Feb 15 2007 4:39 PM
So on Windows 20003, running .Net 1.1, I am trying to find a solution to how to change the drive letter of a volume. I have thus for managed to enumerate the volumes on the drive via:
ManagementObjectSearcher query = new 
	ManagementObjectSearcher("SELECT * From Win32_LogicalDisk"); 
ManagementObjectCollection queryCollection = query.Get(); 			

foreach ( ManagementObject mo in queryCollection) 
{ 
	switch ( int.Parse( mo["DriveType"].ToString( ) ) ) 
	{ 
		case Removable: //removable drives 
			break; 
		case LocalDisk: //Local drives 
			Console.WriteLine( "Local drive found:\t" + mo["Name"] );
			break; 
		case CD: //CD rom drives 
			Console.WriteLine( "Local CD found:   \t" + mo["Name"] ); 
			break; 
		case Network: //Network drives 
			break; 
	} 
}
Which works great for determining what drive letter it is and what KIND of drive it is. But I can't find the magic bullet that allows me to actually alter the drive letter itself. I found some references to WMI in script to do it:

Active Experts Website link

But my n00bie brain is having a hard time finding the equivalent piece of code in c#. Thanks everyone.