2013-03-16

Drive letters

Everybody knows that Windows has mapped letters for drives and partitions. c:\windows or c:\program files are familiar notions to Windows users.

There is a big probability that you have only two drives on your computer, C: as hard drive and D: as DVD/Blu-Ray drive. The days when one had A: and/or B: drive are long gone. A: and B: were reserved for floppy disk drives. These drive letters can be reused if ones goes to „Administrative Tools -> Computer Management -> Storage -> Disk Management”.

Here is one for you: Why doesn't Windows use A: and B: for USB flash drives? It doesn't do that even if it doesn't have other letters at disposal! This has proven to be a very effective way of disabling USB flash drives from being mounted, as seen below:


The USB flash drive was insterted but Windows couldn't mount it! No error message is being given to the user either. Nothing happens!

Starting with Windows Vista by default one cannot simply create files and directories on drive C:, you either disable the UAC (User Access Control) or comply with this rule.

I used to have my hard disk partitioned as C: for Windows and other programs and D: for my projects / files. But at times I would have less space on D: and I was forced to move data to C: drive. This was a bit annoying.

After installing Windows 8 on a fresh SSD drive I've decided to have only one partition and one fake one. I've substituted a directory for a drive letter. "subst c:\users\cristian\D d:" was the magic line.

In order to change the label of my new D: drive I had to create a registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\D\DefaultLabel) and then I had the label "Data" for D: as I used with my Windows 7 system:


Unfortunately Total Commander doesn't know about this trick and it displays the same drive label for D: as it does for C:

Soon I've noticed that my emulated D: drive was visible just for me, it was not usable for programs ran as Administrator. This turned to be a letdown, I had to run "subst c:\users\cristian\D d:" from a cmd.exe shell ran as Administrator. Couldn't be a way to run this script for both users?

Fortunately "Andres" had published on stackoverflow a solution to run a cmd.exe shell script as Administrator. His solution uses a hybrid shell script which is a valid cmd.exe shell script and also a WSH JScript.

Now I had a script which runs "subst c:\users\cristian\D d:" from my user and also from the Administrator user. Cool! I've put this script in the "Start Up" and now I have a fully functional D: drive!

@if (1==1) @if(1==0) @ELSE
@echo off&SETLOCAL ENABLEEXTENSIONS
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
    @subst d: %USERPROFILE%\D
    cscript //E:JScript //nologo "%~f0"
    @goto :EOF
)
@subst d: %USERPROFILE%\D
@goto :EOF
@end @ELSE
ShA=new ActiveXObject("Shell.Application")
ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+"\"","","runas",5);
@end 

I like this solution. Now when I boot my machine I see UAC prompting me to run this script, which is also a nice way to inform me that my D: drive is mounted.
Post a Comment