Limit range of drive letters that can be assigned to USB drives?

Page 1 of 2 12 LastLast
  1. x509's Avatar
    Posts : 500
    Windows 10 Pro
       #1

    Limit range of drive letters that can be assigned to USB drives?


    I have these scripts that I use with some specific external drives, let's say I: and J:. the scripts require that the external drive always have the same letter.

    The issue is that if another USB drive was plugged in first, and Windows assigned either I: or J: to this other drive. So when I plug in my specific external drive, it gets a different drive letter and I have to move drive letters around with Administrative tools, Disk Management, before I can run my scripts.

    Any way to tell Windows to never give out some drive letters to a random USB drive?
      My ComputersSystem Spec

  2. Steve C's Avatar
    Posts : 4,106
    Windows 10 Pro 64 bit
       #2

    Good question!
      My ComputersSystem Spec

  3. Try3's Avatar
    Posts : 2,431
    Windows 10 Home x64 and Pro x86
       #3

    I adopted a different approach for the scripts I have for using specific external drives. I have a batch file, used as a subroutine for others, that accepts a passed argument of drive label and returns the drive letter [it also works the other way around].

    I set* a meaningful drive label for my backup drives [in your case, your drives I J] and then use my batch file to get the drive letter currently being used by the drive that has that label.
    * When I first set up a new drive after purchase, I check that the label has 'taken' by looking at the drive Properties not just at how it is displayed in File explorer because I have, quite surprisingly, found differences recently.

    So, my script controlling a backup has these lines when retrieving the drive letter of a drive labelled Fred
    Code:
    Set /a FredValue=0
    Set ThisTest=Fred
    Call C:\Tools\IdentifyDrives.bat %ThisTest%
    :: If result is a two letter string [a successful result is a letter and a colon], Fred is connected
    If "%DriveResult:~2%"=="" (Set /a FredValue=1) & (Call :GetOnWithIt)
    GoTo EndFredBackup
    - The variable %DriveResult% identifies which drive letter the drive labelled Fred currently has.
    - My variable %FredValue% is used in decision points later in the script {e.g. If %FredValue% EQU 0 GoTo EndFredBackup}
    - My subroutine :GetOnWithIt is the section of code that runs the backup
    {All my scripts are within subfolders of C:\Tools as explained in my post Set up my Tools folder ditty - TenForums}

    The batch file doing the assessment is
    IdentifyDrives.bat
    Code:
    :::::::::: Pass drive label or drive letter when calling this script and get back drive letter or drive label ::::::::::
    :::::::::: - i.e. pass one, get the other ::::::::::
    :::::::::: - The output is the variable DriveResult ::::::::::
    :: Initialisation
    Set DriveResult=
    
    :: Assess passed argument
    :: Remove any quotes
    Set ThisPassed=%~1
    :: Bail out if no parameter had been passed
    If "FFFFFFFF"=="FFFF%ThisPassed%FFFF" GoTo EndIDDrives
    :: Remove any colon
    Set ThisPassed=%ThisPassed::=%
    :: If ThisPassed is a single letter it must be a drive letter and I must want to get the label
    If "%ThisPassed:~1%"=="" GoTo GetDriveLabel
    :: Otherwise ThisPassed must be a label and I must want to get the drive letter
    GoTo GetDriveLetter
    
    :: Passed drive label, get drive letter [including colon]
    :GetDriveLetter
    for /f "tokens=1,2" %%D in ('wmic volume get DriveLetter^, Label') do Call :CheckLabels %%D %%E
    If "%DriveResult%"=="" (Set DriveResult=PassedParameterNotFound) & GoTo EndIDDrives
    GoTo EndIDDrives
    
    :CheckLabels
    :: Further processing required to avoid labels being misidentified
    :: - FredBig, Fred, FredSmall would otherwise all get a hit on finding Fred
    :: Check that the found label is an exact match for ThisPassed
    If /I "%2"=="%ThisPassed%" Set DriveResult=%1
    GoTo :EOF
    
    :: Passed drive letter [including colon], get drive label
    :GetDriveLabel
    for /f "tokens=2"  %%D in ('wmic volume get DriveLetter^, Label ^| find /I "%ThisPassed%:"') do Set DriveResult=%%D
    If "%DriveResult%"=="" (Set DriveResult=PassedParameterNotFound) & GoTo EndIDDrives
    GoTo EndIDDrives
    
    :EndIDDrives
    Pause at EndIDDrives during testing - DriveResult is %DriveResult%

    The code can also cope with passing a drive letter and getting back a drive label but I have yet to find a single example of that being useful.

    Denis
    Last edited by Try3; 6 Days Ago at 05:28.
      My ComputerSystem Spec

  4. Try3's Avatar
    Posts : 2,431
    Windows 10 Home x64 and Pro x86
       #4

    I don't understand the colour coding scheme used in TenForums code boxes so here's an imperfect alternative display of the code I posted above.
    Click image for larger version. 

Name:	Shown in Word.png 
Views:	1 
Size:	63.1 KB 
ID:	246878

    Colour codes:
    blue - comments
    mauve - variable processing
    brick red - decision processing
    green - program flow
    light blue - brackets
    orange - external commands


    Denis
    Last edited by Try3; 6 Days Ago at 06:26.
      My ComputerSystem Spec

  5. Kari's Avatar
    Posts : 16,319
    Windows 10 Pro
       #5

    When I customize Windows deployment images, I copy Windows ISO contents to a folder D:\ISO_Files. I can then mount the image, edit it, add answer files and customizations and so on.

    When done, I use this simple batch file to copy the customized install files to a USB Flash drive. It looks for an USB Flash drive with label W10-USB, gets its drive letter, formats it giving it the same drive label (W10-USB), and finally copies the contents of folder D:\ISO_Files to that USB drive:

    Code:
    @ECHO OFF
    for /f %%X in ('wmic volume get driveletter^, label ^| find "W10-USB"') do set USBDRIVE=%%X
    format %USBDRIVE% /fs:NTFS /v:W10-USB /q
    echo.
    echo Copying D:\ISO_Files to drive %USBDRIVE%
    xcopy D:\ISO_Files\*.* /s /e /q %USBDRIVE% /i /k
    echo .
    echo D:\ISO_Files copied to USB drive %USBDRIVE%
    echo.
    pause

    I have the batch file saved as CopyToUSB.bat in my %userprofile%\OneDrive\Scripts folder. The batch reads USB drive W10-USB's letter to variable %USBDRIVE%, and uses it in format and xcopy commands. As long as I use the same USB flash drive label (W10USB), I don't have to know its drive letter.

    Click image for larger version. 

Name:	image.png 
Views:	3 
Size:	333.4 KB 
ID:	246879

    Kari
      My ComputerSystem Spec

  6. x509's Avatar
    Posts : 500
    Windows 10 Pro
    Thread Starter
       #6

    Kari said: View Post
    When I customize Windows deployment images, I copy Windows ISO contents to a folder D:\ISO_Files. I can then mount the image, edit it, add answer files and customizations and so on.

    When done, I use this simple batch file to copy the customized install files to a USB Flash drive. It looks for an USB Flash drive with label W10-USB, gets its drive letter, formats it giving it the same drive label (W10-USB), and finally copies the contents of folder D:\ISO_Files to that USB drive:

    Code:
    @ECHO OFF
    for /f %%X in ('wmic volume get driveletter^, label ^| find "W10-USB"') do set USBDRIVE=%%X
    format %USBDRIVE% /fs:NTFS /v:W10-USB /q
    echo.
    echo Copying D:\ISO_Files to drive %USBDRIVE%
    xcopy D:\ISO_Files\*.* /s /e /q %USBDRIVE% /i /k
    echo .
    echo D:\ISO_Files copied to USB drive %USBDRIVE%
    echo.
    pause

    I have the batch file saved as CopyToUSB.bat in my %userprofile%\OneDrive\Scripts folder. The batch reads USB drive W10-USB's letter to variable %USBDRIVE%, and uses it in format and xcopy commands. As long as I use the same USB flash drive label (W10USB), I don't have to know its drive letter.

    Click image for larger version. 

Name:	image.png 
Views:	3 
Size:	333.4 KB 
ID:	246879

    Kari
    Guys,

    I'm amazed at the ingenuity in these scripts, but most of my scripts are actually "jobs" in programs like GoodSync and Retrospect. They only work if they find the external drive at the drive letter built into those "jobs." Retrospect in particular, it is very, very particular about drive IDs and drive letters.

    I have made unforced user errors ( ) because I plugged in a USB drive and then did some work, without first checking the drive letter that Windows assigned. Those user errors would eliminated if I could map "other" USB drives away from the drive letters I want to reserve.

    - - - Updated - - -

    Kari said: View Post
    When I customize Windows deployment images, I copy Windows ISO contents to a folder D:\ISO_Files. I can then mount the image, edit it, add answer files and customizations and so on.

    When done, I use this simple batch file to copy the customized install files to a USB Flash drive. It looks for an USB Flash drive with label W10-USB, gets its drive letter, formats it giving it the same drive label (W10-USB), and finally copies the contents of folder D:\ISO_Files to that USB drive:

    Code:
    @ECHO OFF
    for /f %%X in ('wmic volume get driveletter^, label ^| find "W10-USB"') do set USBDRIVE=%%X
    format %USBDRIVE% /fs:NTFS /v:W10-USB /q
    echo.
    echo Copying D:\ISO_Files to drive %USBDRIVE%
    xcopy D:\ISO_Files\*.* /s /e /q %USBDRIVE% /i /k
    echo .
    echo D:\ISO_Files copied to USB drive %USBDRIVE%
    echo.
    pause

    I have the batch file saved as CopyToUSB.bat in my %userprofile%\OneDrive\Scripts folder. The batch reads USB drive W10-USB's letter to variable %USBDRIVE%, and uses it in format and xcopy commands. As long as I use the same USB flash drive label (W10USB), I don't have to know its drive letter.

    Click image for larger version. 

Name:	image.png 
Views:	3 
Size:	333.4 KB 
ID:	246879

    Kari
    Guys,

    I'm amazed at the ingenuity in these scripts, but most of my scripts are actually "jobs" in programs like GoodSync, Beyond Compare, and Retrospect. They only work if they find the external drive at the exact drive letter built into those "jobs."

    I have made unforced user errors ( ) because I plugged in a USB drive and then did some work, without first checking the drive letter that Windows assigned. Those user errors would eliminated if I could map "other" USB drives away from the drive letters I want to reserve.
      My ComputersSystem Spec


  7. Try3's Avatar
    Posts : 2,431
    Windows 10 Home x64 and Pro x86
       #7

    Then it seems to me that your only option is to assign drive letters that will not get used by anything else - assign YZ instead of IJ.

    Denis
      My ComputerSystem Spec

  8. x509's Avatar
    Posts : 500
    Windows 10 Pro
    Thread Starter
       #8

    Try3 said: View Post
    Then it seems to me that your only option is to assign drive letters that will not get used by anything else - assign YZ instead of IJ.

    Denis
    I was hoping that would not be the answer, but what is, is. Even with this approach, I have 4 different external USB drives that are part of these scripts, so I would still have the issue of matching the drive to a specific letter.

    I wish there was some way to submit a feature request to Microsoft.
      My ComputersSystem Spec

  9. Try3's Avatar
    Posts : 2,431
    Windows 10 Home x64 and Pro x86
       #9

    If you assign them [once only] to WXYZ using Disk mgmt {C:\Windows\System32\diskmgmt.msc} or something like MiniTool Partition Wizard then they will retain those drive letters when they are re-connected unless
    - you first connect 19+ other drives at the same time as your desired drives so that the computer is forced to re-use W then X then Y then Z
    - you do a Windows 10 Version update - drive assignments do need to be checked afterwards [but this has only messed up drive assignments a couple of times].
    - [added 14 Sep 2019] - some Cumulative updates can mess up drive letter assignments as well. KB4515384 does so on one of my computers [but not on the others].

    You could use the Feedback hub to suggest that change but, as explained, I think Windows can already achieve what you want without any change being necessary.

    Denis
    Last edited by Try3; 2 Days Ago at 04:49.
      My ComputerSystem Spec

  10. x509's Avatar
    Posts : 500
    Windows 10 Pro
    Thread Starter
       #10

    Denis,

    Thanks. After re-reading your previous message, I think that I can mark this thread SOLVED.

    Appreciated.
      My ComputersSystem Spec


 
Page 1 of 2 12 LastLast

Related Threads
Solved Change assigned drive letters in Drivers and Hardware
Haven't done this in a while. Never in W-10 Want to move and reassign: On Disk 0 (F) becomes (D) 15 MB assigned by OS On Disk 1 (H) becomes (E) Second SSD drive On Disk 2 (D) becomes (F) First HDD used for storage On Disk 3 (E)...
Hi, I run a backup script to different USB drives at different times. The backup script always needs to see the same drive letter for the USB drive (whichever USB drive is being used). I know you can run compmgmt.msc, select Disk...
I have many systems in house that have dual USB hdd docks. These normally have two drives installed. I have assigned specific drives letters via disk manager. However when another USB storage device is added the drive letters for the two...
Greetings, Just one practical question. How do I assign a range of letters, that can be used for e.g. external flash disks, external ssd's/hdd's or memory cards? I have this nasty issue. I have two Network Attached Drives, on server. They work...
Hi I have a strange problem. I have some harddrives on a "server" computer in my homenetwork running win 7. From my "client" running windows 10 I am mounting these drives using psexec \\server -u username -p password -d net share F=F:\...
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 17:50.
Find Us