Introduction (The Project in Less than 30 40 47 Words)
Recently, I was facing a problem I never thought could be an issue. If you have a pool of hard discs that you connect to a computer, the drive letter seems not to be constantly the same.
Here is a practical approach to handle it.
The Code
Background
The Problem in Detail
When you connect different hard discs (in my case by eSATA) and you want them to always have the same drive letter, you face the problem that the drive letter is not constantly the same. It seems to be a problem to have (in my case eight) drives out of a pool of 16 to have the same drive letter when they are connected. This could be a problem if you shared the drive, e.g., for using the drive as a backup target.
I’m not talking about situations where the drive letter is used by another drive or multiple drives are connected. I am talking about a scenario where two drives out of a pool of 16 are connected the same time. (Mo – The media and 4 Fr media sets.)
The Idea
I guessed Windows is putting all connected drives to a list when I manually assign a custom drive letter to it. This works in my tests as long as you always assign different drive letters. If you have two drives, you want to have the K letter for example, it works only for the last manually assigned drive. If you connect the other one, it gets the first free drive letter. (Tested on Windows Server 2012 R2, Windows 10 Pro.)
So, if Windows is not ”willing” to track the drives, we have to put them on our own list.
All you need now is the drives guid, that every drive (& volume) has and the target drive letter.
The Result
With a little WMI magic, we can iterate through all connected drives (locally, USB, SATA) and change or remove the drive letter.
Putting all the requirements with the magic together will bring us to the concept to have a small application that reads a list of drives from a text file, remove any eventually already used drive letter and finally reassign all drive letters based on the lists data.
Sounds simple, huh?
How to Use It
First of all, the application can only work when run as administrator because standard users are not allowed to change the drive letter.
When the application is started without a parameter, it will list up all currently connected (they actually don’t need to have a drive letter) drives and volumes to the screen and also to a text file called “CurrentDrives.txt” in the application directory.
The written text file looks like this:
In my case, you see that my c drive is connected and the letter p
is assigned to the connected USB thumb drive.
As you notice, my system as also three partitions (or volumes) that currently do not have any assigned drive letters. These are the recovery partition(s) and the hidden Windows partition, which Windows creates at setup.
To make the application change the drive letter, you have to create a text file which contains the drive guid followed by a TAB and followed by the drive letter it should get. (You can copy and paste it out of the just generated text file).
If I would like to change the drive letter of the thumb drive from p
to t
, this is the file:
Please have in mind, you need to be administrator to change the drive letter !
What’s Next, Further Thoughts
In my case, I use the application as a scheduled task at a fixed time. But what I could think about is, to run it once an external media is connected. This could be bound to the occurrence of an event in the task scheduler. The source is also added, feel free to play around.
Sideproject
As a side project, I prepared another tool called DriveLetterMaker
, based on the idea of snoopy001
here in the comments section. (With a little update form my side...)
The idea behind DriveLetterMaker
is that the device that you connect contain a textfile
called Make_Me_Drive_X.txt which defines which drive letter it should be. When the tool runs, it removes any existing drive letter for that column and assigns the one from the filename. The content of the text file is not read, so it doesn't matter at all. This will reduce the handling effort with the long list of volume guids.
Here are the files:
History
- 24.01.2018: Release version 1.00
- 26.01.2018: DriveLetterMaker version 1.00 added