Jump to content

Reassigning drive letters automatically

Recommended Posts

Here is the batch description:

:: -------------------------------------------------------------------------------

:: MapDrive.cmd: Assign letters to Drives

:: ------------

:: Purpose: Automatic assignement of new letter to drives without reboot.


:: Parameters:

:: ----------

::    1. Language ID (ENU, FRA, DEU, NLD,...).  No default value, mandatory.

::    2. TEST to do everything except the drives de/re-assignment.  The log file

::        TMP_MAPDRIVE_date_time.LOG is created: you can display it to see the expected assignments.

::        The environment variables TMP_VOLDESC- show the assignments to be done.

::    3. TempPath : Path where temporary files will be created.  Default is current directory.

::        Path could be enclosed in quotes and could terminated by a backslsh.

::        This is the 2d parameter if the 1st one (TEST) is omitted.


:: Why this program?

:: ----------------

::    Because during unattended Windows installation, I didn't want to reassign

::    manually my drives (S: for Save, W: for my CD Writer, V: for my DVD, T: for

::    temporary data, U: for backups, G: for games,...)


:: How to use it?

:: -------------

::    1. Create a file DRIVE.x on each drive to be reassigned as x:.

::    2. On the system drive, create a file CDR.x where x is the letter to assign

::        the the CD reader[/writer].  For unattended installation, create this file

::        in $OEM$\$1\.

::    3. In the same way, create a file DVD.x for the DVD reader[/writer] on the system drive.

::    4. On the system drive, create a DRIVE-.x for each letter x that you don't want

::        to be assigned (= reserved letters for USB Key,...).

::    5. For unattended Windows installation, (FRA for French,...)

::            add these lines in the file RunOnceEx.cmd

::                (they should be modified according to your situation):

::                SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

::                REG ADD %KEY%\001 /VE  /D "Modifying Drives Letters" /f

::                REG ADD %KEY%\001 /V 1 /D "%SystemDrive%\Install\MapDrive.cmd FRA >%SystemDrive%\MapDrive.log 2>&1" /f

::            or add one of these lines in CMDLINES.TXT (under [COMMANDS]):

::                "MapDrive.cmd FRA %SystemDrive%\Temp >%SystemDrive%\Temp"

::                "MapDrive.cmd FRA TEST %SystemDrive%\Temp >%SystemDrive%\Temp"


:: Before running:

:: --------------

::  - If your windows language is not in the language ID set (see above in the "Parameters", 1.),

::    you should have the correct value in the environment string STR2FIND.

::    To do that, you should put a part of the answer DISKPART display when you

::    try to modify a reassignable drive letter.

::    To find this string, execute the following (without the text in () which are comments):

::        DISKPART

::        LIST VOLUME

::        SELECT VOLUME x (select an n on-system drive)

::        ASSIGN LETTER d (the same as the current letter)

::                        (DISPART display the message that you should take)

::        SELECT VOLUME y (select the system drive)

::        ASSIGN LETTER e (the same as the current letter of the system drive)

::                        (DISPART display an error message telling you that you

::                        ( cannot reassign the letter for a system drive, boot

::                        ( drive or a drive qhere is the swap file)

::        EXIT

::    You should take a part of the first message which is not in the second

::    message, and stop the string on accentuated characters.


:: Notes:

:: -----

:: When run, MapDrive.cmd scans all the drives (volumes) for files matching

::    "\DRIVE.?".  If the file "\DRIVE.d" is encountered on a volume, this volume

::    is reassigned with the letter "d:".

:: Do not forget that the system drive as well as the drive containing the page

::    file (and others) could not be reassigned.

:: You may also reassign CD/DVD letters by creating one or many files "\DVD.d"

::    and/or "\CDR.d" on the system drive.

:: You may also disable drive letters by creating one or many files "\DRIVE-.d"

::    on the system drive.


:: This script works on FAT32 and NTFS file system.  this is not the case for

::    MOUNTVOL which accepts only NTFS.  Furthermore, no reboot is required.


:: The drives which are already assigned to the "good" letter will not be removed

::    nor reassigned.


:: IMPORTANT:  I am not responsible for any damage caused directly or indirectly

::    by this program.  So, before using it, run this batch with TEST as second parameter.

:: -------------------------------------------------------------------------------

EDIT: If your Windows language is English, German, Dutch or French, you don't have to worry about all of that: just call

MapDrive ENU, or MapDrive DEU, MapDrive NLD or MapDrive FRA.


Current attachement version is 2008/08/04:

:: 2008/08/04 : Dutch language added (Thanks to Orcinus)

:: 2005/10/30 : Reassigning twice (to avoid bad assigning to a used letter)

:: 2005/10/28 : Try to keep the existing letters.

:: Group deasignments and reassignments.


Keywords: drive drives partition partitions letter letters volume volumes mapdrive drivemap diskpart change changing rename renaming modify modifying



Edited by mdes
Link to comment
Share on other sites

Good job, i quickly read the script and i understand how it works. I will test it next time.

But for non french version, there is a problem

Line 99 you use --> FIND /C "La lettre sp"

The string is in french so in other language version, the string won't be find.


Link to comment
Share on other sites

But for non french version, there is a problem

Line 99 you use -->  FIND /C "La lettre sp"

The string is in french so in other language version, the string won't be find.

You are right :) I added comment in the post and in the batch file to tell how to change this string.

Link to comment
Share on other sites

now honestly, is it reliable? :rolleyes:

Yes it has been tested :D

The only problem I encountered is that, sometimes (it depends of the installed Windows), the CD drive is not reassigned when there is a CD in the tray. I found why: the output file of DISKPART is UNICODE, so there is 2 characters at the file beginning. I will solve this problem in a few hours :)

EDIT: Sould be solved now: This was not a UNICODE problem but LF instead of CRLF.

Edited by mdes
Link to comment
Share on other sites

I've tried running this on a Ghost 8 PC-dos boot disk (floppy) to boot to a lan mount of the Install/Windist dir,

it no worky fo me

I get this spew about

"Out of environment space"

"Bad command or filename"

can someone explain how to run this mapdrive.cmd on an unattended install

(obviously prior to install so my D and E are in the right place)

I'm trying to accomplish this on a dual boot (xp/2K) machine :)

(2 C:'s (each hidden from each other), 2 D:'s, and 1 E:)

Link to comment
Share on other sites

Yes, MapDrive.cmd use a lot a environment space :) Here is a solution:

In CONFIG.SYS, add the following line

shell=C:\cmd.com /P /E:nnn

where n is the number of bytes you want to set aside for the environment. For DOS 6.22 nnn represents the number of bytes you want to set aside. So for a 2K environment take nnn=2048 (try with a larger value, e.g. 8192 or more)

About ""Bad command or filename", I suppose this is a consequence of the out of environement space.

For unattended, I am using the following:

File command.txt


File RunOnceEx.cmd

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx...REG ADD %KEY%\800 /VE  /D "Modifying Drives Letters" /fREG ADD %KEY%\800 /V 1 /D "%systemdrive%\Install\MapDrive.cmd" /f...
Link to comment
Share on other sites

shell=C:\cmd.com /P /E:nnn

Thanks eh! :)

saw that on one of my anicent config.sys's, was wondering what that was lol

question: is that ram or cache and how far could you go with say:

256K cache=?

512K cache=?

256Meg Ram=?

1024Meg Ram=?

File RunOnceEx.cmd

Didn't know it could be run that late in the game eh. Awesome :rolleyes:

(but before anything else of course)

Link to comment
Share on other sites

k not getting any environment errors,

(although 8192 might be a little high; and it stopped NET.exe from from doing something, I still got in.)

but still getting syntax erros and bad command or filename

(repeated about 20-30 times)

just tried running diskpart

says it cannot be run under dos

so i guess its the runonceex method eh

question about that then,

Won't I need it to run before the os even gets installed so that my folder redirections will work?



or is the 12/13minute mark going to be ok for that?

(runonceex launched from/in commandlines.txt) or is it going to have to be put someplace sooner?

Link to comment
Share on other sites

doh! n/m just stuck it 2nd in the list. :)

REG ADD %KEY%\001 /VE /D "Turning system restore off" /fREG ADD %KEY%\001 /V 1 /D "REGEDIT /S Z:\SCRIPTS\sysresoff.reg" /f
REG ADD %KEY%\002 /VE  /D "Modifying Drives Letters" /fREG ADD %KEY%\002 /V 1 /D "Z:\SCRIPTS\MapDrive.cmd" /f
REG ADD %KEY%\003 /VE /D "Setting Personal & Settings Folders Redirects" /fREG ADD %KEY%\003 /V 1 /D "REGEDIT /S Z:\SCRIPTS\Redirect.inf" /f

that should do it eh :rolleyes:

but i'm still stuck on this tho :D


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...