Assign Drive Letter by Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
johnbil
Posts: 11
Joined: 06 Jul 2013 09:01

Assign Drive Letter by Batch File

#1 Post by johnbil » 16 Feb 2016 21:01

I have been having some problems with an external Sata hard drive on my PC. I assign it a specific letter, but when I reboot, the drive does not maintain its letter. The drive itself is new, but I also had the same problem with another drive.

If this problem can’t be fixed, I would like to create a batch file to assign the drive a specific letter quickly and automatically rather than doing it manually through ‘Computer Management’.

Does anyone know the wording, which I should use in the batch file? Any help would be appreciated.

JohnB

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Assign Drive Letter by Batch File

#2 Post by Squashman » 16 Feb 2016 21:26

I believe you could use DISKPART or MOUNTVOL.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Assign Drive Letter by Batch File

#3 Post by foxidrive » 17 Feb 2016 00:38

johnbil wrote:I have been having some problems with an external Sata hard drive on my PC. I assign it a specific letter, but when I reboot, the drive does not maintain its letter.


Is it USB? Try setting the drive to a higher letter in an area that will not be reached with other devices, using Disk Management.

S: or even Z: etc.

johnbil
Posts: 11
Joined: 06 Jul 2013 09:01

Re: Assign Drive Letter by Batch File

#4 Post by johnbil » 17 Feb 2016 22:01

I tried DISKPART, but couldn't figure out how to input the criteria at the prompt via the batch file.

Assigning Z: as the drive letter seems to have the letter maintained in the next session. :)

Thanks for the advice guys.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Assign Drive Letter by Batch File

#5 Post by foxidrive » 18 Feb 2016 02:10

johnbil wrote:Assigning Z: as the drive letter seems to have the letter maintained in the next session. :)


What happens with USB is that the first available drive letters get shuffled as USB devices get added, removed, and changed.
Nothing remains stable wrt those drive letters.

Elwood
Posts: 1
Joined: 18 Feb 2016 04:05
Location: Lyon, France

Re: Assign Drive Letter by Batch File

#6 Post by Elwood » 18 Feb 2016 06:53

Hi,

I had the very same problem on a disk that should appear as E:
Here is what I do automatically upon the computer start:

if exist E:\ goto :eof
echo select volume 3 >%tmp%\script.txt
echo assign letter E >>%tmp%\script.txt
diskpart /s %tmp%\script.txt rem run diskpart with the correct answers

So basically:
if drive is here, exit
generate a response file for diskpart
run diskpart with the correct answers

Post Reply