Change the Drive Letter of a Volume

Changes the drive letter of volume D to Q. If you modify this script to change the drive letter of a volume other than D, note that the volume name in the WQL query must include b

 
 
 
 
 
(0)
Add to favorites
Storage
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • My implementation not working!
    1 Posts | Last post January 30, 2017
    • Hi there,
      was pretty glad to find this snippet! The original script works fine! But when I tried to change the sourceDrive letter to a variable - it fails!
      My changes:
      
      Dim CompStr As String = String.Format("Select * from Win32_Volume Where Name = {0}", strSourceDrive)
      colVolumes = objWMIService.ExecQuery(CompStr)
      
      The String is as correct as the original, as strSourceDrive is: "'X:\\'".
      When String.Format put's it all together it exactly reflects the original string.
      So what is wrong with my approach? Any hint would be highly appreciated!
      Best Regards
      Hans
      
  • Can this be tweaked to Locate the USB drive by name and change the letter to "B"?
    1 Posts | Last post April 21, 2016
    • This works perfectly if I already know the drive letter of my USB.  However, I would like to place this little bit of coding directly onto a USB drive named "BACKUP" and have the user double click it to automatically map the BACKUP drive to "B:" so that it will be able to run a backup script I have created that saves the files to the "B" drive.
      
      Is there a code that can be used to locate the USB drive by name and then change the drive letter to "B"?
      
      This is my first time posting to here, but I appreciate any help you can lend.  Thank you.
  • Modify for WinXP/Win7?
    4 Posts | Last post January 07, 2015
    • Is there a way that this script can be used on Windows XP and Windows 7? We are getting ready to swap out about 100 computers and the new computers have card readers that will need to have their drive letters changed so as to not interfere with our login scripts. Thanks,
    • It worked on my Win7 Ult.
    • In Win 7 Pro SP1, sent this error:
      Code 8007009a
      Error: The volume label you entered exceeds the label character limit of the target file system
      Anyone know why?
    • Found out that drive needs to be unmounted first.
      The second script on this pages works perfectly:
      http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_27113594.html 
      
      VBS Script:
      >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
      ChangeDriveLetterWithMountvol "F:", "E:"
      
      Sub ChangeDriveLetterWithMountvol(strSourceDrive, strTargetDrive) 
      
          Dim objShell, objExec
          Dim strVolume
          
          Set objShell = WScript.CreateObject("WScript.Shell")
          
          ' Get volume associated to the old drive letter.
          '
          Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /L")
          strVolume = Trim(objExec.StdOut.ReadLine())
          While objExec.Status = 0
              WScript.Sleep(100)
          Wend
          
          ' Unmount the drive.
          '
          Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /D")
          While objExec.Status = 0
              WScript.Sleep(100)
          Wend
          
          ' Mount the drive on the new drive letter.
          '
          Set objExec = objShell.Exec("mountvol " & strTargetDrive & " " & strVolume)
          While objExec.Status = 0
              WScript.Sleep(100)
          Wend
      
      End Sub