Recipe 3.5. Setting the Drive Letter of a VolumeProblemYou want to set the drive letter of a volume. SolutionUsing a graphical user interface
Using a command-line interfaceThe diskpart command lets you assign driver letters from the command line on Windows Server 2003 and Windows XP. First, start by running the command in interactive mode: > diskpart List the current volumes on the system: > list vol From the output, select the volume in which you want to set the driver letter. In the following command, I'm selecting volume 0: > select vol 0 Now, assign the drive letter you want. In the following example, I'm assigning letter F: > assign letter=F Using VBScript' This code sets the drive letter of a volume. ' The Win32_Volume class is new in Windows Server 2003 ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strOldDrive = "I:" strNewDrive = "J:" ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colVol = objWMI.ExecQuery("select * from Win32_Volume where Name = '" & _ strOldDrive & "\\'") if colVol.Count <> 1 then WScript.Echo "Error: Volume not found." else for each objVol in colVol objVol.DriveLetter = strNewDrive objVol.Put_ WScript.Echo "Successfully set drive letter for volume." next end if DiscussionWhen volumes are made active and removable media are added to a system, they are automatically assigned the next available drive letter (in alphabetical order starting from C:). It is a straightforward operation to change the letter of a drive, but you need to be sure nothing references the prior drive letter. If you attempt to assign a different drive letter to an existing drive that is currently in use, the system will let you do it and allows both the old drive letter and new drive letter to be used until the system is rebooted. After the system restarts, the old drive letter will go back into the pool of available drive letters.
See AlsoMS KB 234048 (How Windows 2000 Assigns, Reserves, and Stores Drive Letters) and MS KB 223188 (How To Restore the System/Boot Drive Letter in Windows) |