Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Change drive letters to your liking

- - - - -

  • Please log in to reply
18 replies to this topic

#1
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • OS:Windows 7 x64
  • Country: Country Flag
:) Sometimes the answer is too easy. When you know what to look for after two days of trying it the hard way.

To change drive letters:
First you have to get the GUID of the drive you want to change and store it somehow.
Then you have to remove the existing drive letter.
Finally you add a new drive letter using the GUID you saved.

WARNING: Use at your own risk!! If you remove/change the drive letter from your boot drive your on your own if you can no longer boot.

The following information was gleaned from the following site:
Microsoft Knowledge Base Article - 280297

echo off
mountvol %1 /L>drive.mnt
Echo Deleting %1 drive
mountvol %1 /D
for /f %%I in (drive.mnt) do set changedrive=%%I
Echo Remounting %1 as %2 drive
mountvol %2 %changedrive%
set changedrive=
del drive.mnt

%1 - old drive letter
%2 - new drive letter

mountvol - included as part of windows xp in %systemroot%\system32 directory.

If anyone knows a way to directly put the output of "mountvol %1 /L" in to a environment variable, post it and I'll change the script.
It seems to me there is a way but I can't come up with it without 3rd party utilities, I'm just a bit out of practice with cmd/bat files.

For those looking to change CD-ROM drive letters I earlier posted a program (Detectcd.exe) earlier which will set a system environment variable to each cd-rom drive in the system.
Then you can then use the variables to change your drive letters and if you plan to use the environment variables rerun DetectCD to reset the variables to the new drive letters.
see: http://www.MSFN.org/...topic=10798&hl= for DetectCD


How to remove advertisement from MSFN

#2
captdilly

captdilly

    Newbie

  • Member
  • 19 posts
That's a good one, heres one that I found in VBS form

' Script that changes drive letters
' Note: Do NOT use it on SYSTEM or BOOT partition drive letters !!!
' Author: Torgeir Bakken

sComputer = "."
Const HKLM = &H80000002

' from/to
If ChangeDrvLetter("E:", "Z:") Then
  WScript.Echo "Drive letters changed, please reboot to see the change!"
Else
  WScript.Echo "Failed changing drive letters!"
End If


Function ChangeDrvLetter(sSourceDrive, sTargetDrive)
  bOK = True  ' Init value
  Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
     & sComputer & "\root\default:StdRegProv")

  sKeyPath = "SYSTEM\MountedDevices"
  sSrc = "\DosDevices\" & UCase(sSourceDrive)

  iRC = oReg.GetBinaryValue(HKLM, sKeyPath, sSrc, sValue)

  If iRC = 0 Then
    sTrg = "\DosDevices\" & UCase(sTargetDrive)

    iRC = oReg.SetBinaryValue(HKLM, sKeyPath, sTrg, sValue)

    If iRC = 0 Then
      oReg.DeleteValue HKLM, sKeyPath, sSrc
    Else
      bOK = False
    End If
  Else
    bOK = False
  End If
  ChangeDrvLetter = bOK
End Function


Just change the par thtat says If ChangeDrvLetter("E:", "Z:") Then To the letter's you want to change (The one shown would change drive E: to drive Z: for example)

#3
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • OS:Windows 7 x64
  • Country: Country Flag
Nice, but reboot is required. Which is where my problem was in my scripts for my unattened installs. Mine requires no reboot changes are immediate.

#4
baliktad

baliktad

    Stellar Underachiever

  • Member
  • PipPip
  • 155 posts
If you're using Windows XP or above, might I suggest using the diskpart tool. It's included with the OS and completely scriptable. Also it removes the need for dangerous scripting (reassigning letters to system/boot volumes) and doesn't need a reboot.

If you're unfamiliar with diskpart, have a look at ntcmds.chm in your %systemroot%\help folder for full documentation. I'll only talk here about reassigning drive letters.

To use diskpart in an unattended mode, simply put the commands you would type in the console in a text file instead and run diskpart /s scriptfile.txt.

Now, the syntax. diskpart is a command-line driven tool. Most operations involve selecting a particular disk, partition, or volume, and then executing a command on that object. To change around drive letters, here's an example script I use. I've indented every other line for aesthetic purposes only.
select volume 7
   assign letter B
select volume 4
   assign letter E
select volume 5
   assign letter F
select volume 6
   assign letter G
select volume 0
   assign letter H
select volume 1
   assign letter I
A listing in diskpart of all volumes afterwards yields the following:
 Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     H                       CD-ROM          0 B
  Volume 1     I                       DVD-ROM         0 B
  Volume 2     C   SYSBOOT      FAT32  Partition     55 MB  Healthy    System
  Volume 3     D   WINXP        NTFS   Partition     15 GB  Healthy    Boot
  Volume 4     E   EXTRA        NTFS   Partition     15 GB  Healthy
  Volume 5     F   SOURCE       FAT32  Partition     29 GB  Healthy
  Volume 6     G   Monster      NTFS   Partition     56 GB  Healthy
  Volume 7     B                       Removeable      0 B
The volume numbers do not change so you are safe to refer to your volumes via number as I do in my script above. You can also refer to them by letter however (e.g. select volume b). If you list the volumes in your current configuration, you should be able to figure out what select and assign operations you'll need to get your drive letters right.

I haven't found a way to assign letters according to drive type, but if you're astute you'll notice that diskpart assigns volume numbers in a regular fashion (optical, physical, removable). I haven't experimented with a large number of system configurations (secondary hard disks, SATA drives, etc) though, so test your scripts first!

This is only a tiny portion of what diskpart can do, it's very good for automating creation/removal of partitions (resizing limited to extending NTFS volumes) prior to installation and also diagnostic purposes. (Big Hint: diskpart is an ideal tool to use in Windows PE just before you install Windows if you're doing any sort of automated partition work.)

Feel free to post any questions, and as always, comments and suggestions are welcome.

#5
mdes

mdes

    Advanced Member

  • Member
  • PipPipPip
  • 343 posts
Thanks for the infos.

I would like to change the volume letter according of the volume label. E.g. if a volume name contains "-D-", the new letter should be "D:".

Furthermore, This should be done for a new unattended Windows installation.

Any idea ?

Michel.

ps:
* What about the sequence order of ASSINGments : if I would change a letter to "D:", but if another drive is already "D:" (but it will be remaned to "X:" after) ?
* I could be easyer to write a .vbs, but when to execute it so the assigments will be token for the new Windows installation ?
Windows XP Pro French + SP2 Many Thanks to GreenMachine XPCREATE
Michel Dessaintes (nick: mdes) FlashList for genealogy, CongésRFV for Pocket PC

#6
big poppa pump

big poppa pump

    Damn Newbies!!

  • Member
  • PipPipPip
  • 406 posts
One question though, what would be the ideal place/path for the scriptfile.txt ?

DFI LP UT NF4 SLI-DR Expert || Opty 165 CCBBE 0610DPMW @ 3.01Ghz (335*9) - 1.52V, TT Big Typhoon w/120mm Panaflo
2 x G.SKILL F1-4000USU2-2GBHZ || BBA Radeon 1900XTX || X-Mystique DD 5.1 with/ Pioneer THX 1015TX
2*74GB Raptors - Raid 0 || 2*300GB Seagate 7200.9 NCQ SATA-II || 4*Hitachi 500GB 7K500 || Mad Dog Triple Format DL DVD+/-RW/DVD-Ram
OCZ GameXstream 700W || CM Stacker STC-01 || 2 * Dell 2405FPW


#7
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • OS:Windows 7 x64
  • Country: Country Flag
that all depends upon when in your install you want to be able to start using your new drive letters. And how you impletement your installs. If you have things installing to those drives you want to change the drive letter before you install applications, etc to them.

#8
big poppa pump

big poppa pump

    Damn Newbies!!

  • Member
  • PipPipPip
  • 406 posts
Nevermind, I got it! I mananged to use iexpress and combine both diskpart.exe and scriptfile.txt into an installation package and get it working. Thanks for your help though! :)

DFI LP UT NF4 SLI-DR Expert || Opty 165 CCBBE 0610DPMW @ 3.01Ghz (335*9) - 1.52V, TT Big Typhoon w/120mm Panaflo
2 x G.SKILL F1-4000USU2-2GBHZ || BBA Radeon 1900XTX || X-Mystique DD 5.1 with/ Pioneer THX 1015TX
2*74GB Raptors - Raid 0 || 2*300GB Seagate 7200.9 NCQ SATA-II || 4*Hitachi 500GB 7K500 || Mad Dog Triple Format DL DVD+/-RW/DVD-Ram
OCZ GameXstream 700W || CM Stacker STC-01 || 2 * Dell 2405FPW


#9
Gism0

Gism0

    Huh?

  • Member
  • PipPipPip
  • 473 posts
I may be reletivly new to the forum, but why is this in "Networks, Internet and Security" ?
Wise man say, "forgiveness is divine, but never pay full price for late pizza." -Michelangelo

#10
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • OS:Windows 7 x64
  • Country: Country Flag
I accidentally put it in the wrong place, and none has moved it.

#11
Br4tt3

Br4tt3

    World famous sausage eater...

  • Member
  • PipPipPipPip
  • 566 posts
:) Hmmm..... tried the detectcd.exe and changecd.vbs files out! they work great from within Windows, but when I want to apply them from GuiRunOnce / RunOnce they dont dont work out! The variable gets there and everything, but it doesnt change the drive letter of the CD rom unit. I have also tried it from Autostart in tha default profile of the administrator account! Is it possible that the user enviorment isnt loaded or what? I know that drive letters are already assigned when running into the GuiRunOnce section of the sif file...

I wonder, any1???
Sponsored by Swedish Meat!
Tha Sausage Eater...

Please read before posting in forums: http://support.microsoft.com/kb/555375

#12
Gorgonn

Gorgonn
  • Member
  • 5 posts
The thing that always bothers me is having to change the drive letters to my Cdrom/dvd back to M: and N:after I do a clean install. is there any way I can do that before my sif runs runouncex, It would be nice if PE envirment could be set to assign the letter I want.

I have two partitions C and D, E is the ram drive and F and G are the designations windows give my cdrom. wish there was an easy way of switching them to M and N.

#13
frustrated1

frustrated1

    Newbie

  • Member
  • 14 posts
Why all this when you can do it by right clicking my computer, selecting manage / disk management, and right clicking on the device and choosing change drive letters and paths? I know its only for a working system, and you still cant change your boot drive.

#14
prathapml

prathapml

    Follow the rules please :-)

  • Patrons
  • 6,791 posts
  • OS:Windows 8 x64
  • Country: Country Flag
This thread is all about doing it unattended, from a command prompt - at a time when your windows is not yet installed. At such a time, your MyComputer is not available, nor the MMC plug-ins (like DiskManagement).
Posted ImageCheers !!!   Donate to MSFN and Help Keep This Site Running
||Please Read the Forum Rules||  Etiquette   || Welcome to MSFN - Forum Basics || Before posting
prathapml :: MSFN Supermod :: Private Message me if you ever have a problem while at MSFN

#15
Tsunami

Tsunami

    Member

  • Member
  • PipPip
  • 292 posts
Are these GUIDs different every installation? What I really want to do is:

1. Install the driver for my MP3 player. It will automatically create a drive, but I won't know the drive letter, nor the GUID. I want to change the drive letter to B:.

2. Same for my Daemon Tools drives. I want them to be X:, Y:, Z:, but again, I won't know their current drive letter. Can someone confirm that Daemon Tools' drives always have this GUID: \\?\Volume{fd19ed0*-f84b-11d8-a1c6-0010a7086aaa}\ (where * is a number between 1 and 4)?

#16
durex

durex

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 953 posts
Does anyone know if the method baliktad outlines, using the DiskPart utility can be called directly from the cmdlines.txt during the T-12 stage?

Thanks!
Need a free, easy, ad-free place to toss your images? Enjoy.

#17
Bilou_Gateux

Bilou_Gateux

    Powered by Windows Embedded

  • Member
  • PipPipPipPipPip
  • 768 posts
Here my small script i use to silent install applications from a network share using ISO image of the install media.

that way, if customer want to repair an install, he can put the install media in the CD/DVD-ROM drive and msiexec will use the good CDROM drive letter to find the source.

Using:
IcemanND post #1 script code with modifications (no need to use a temp output file).
cdromxp.bat script from Rob van der Woude's scripting pages code.
Bo Branten's filedisk is used to mount / unmount ISO images.

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET WORKDIR=%~dp0
SET IMAGE=040928_1017.iso
SET MSI=Roxio Easy Media Creator 7 Basic Edition.msi
SET LANGUAGE=1036.mst
::alternative: variables defined from command line parameters
::SET IMAGE=%1
::SET MSI=%2
::SET LANGUAGE=%3

:: CHECK AVAILABILITY
FILEDISK /? >NUL 2>&1
IF ERRORLEVEL 1 ECHO FILEDISK wasn't found, please install it and try again

FOR /F "tokens=3" %%A IN ('ECHO list volume ^| DISKPART.EXE ^| FIND.EXE "-ROM "') DO SET CDROM=%%A:
FOR /F "tokens=*" %%B IN ('MOUNTVOL %CDROM% /L') DO SET VOLGUID=%%~B
:: Remove letter assigned to found CD/DVD-ROM drive
MOUNTVOL %CDROM% /D
:: ISO image need to be mounted first as virtual CD
filedisk /mount 0 !workdir!!IMAGE! /cd %CDROM% &ping -n 2 127.0.0.1>nul
:: launch silent install
if exist %CDROM%\%LANGUAGE% msiexec TRANSFORMS=%cdrom%\%LANGUAGE% /i "%cdrom%\%MSI%" /qn REBOOT=ReallySuppress
:: unmount Virtual CD image
filedisk /umount %cdrom% &ping -n 2 127.0.0.1>nul
:: Assign letter to previously unmounted CD/DVD-ROM drive 
MOUNTVOL %CDROM% %VOLGUID%

SET WORKDIR=
SET IMAGE=
SET MSI=
SET LANGUAGE=

:EOF

With some modifications, LANGUAGE MSI and IMAGE variables can be passed from the command line. Haven't yet checked but may not works with msi name containing spaces.
I would like to autodetect the name of msi on CD. In my test there's 2 msi on the CD, the application 'Roxio Easy Media Creator 7 Basic Edition.msi' and one 'ISScript8.msi' used to upgrade InstallShield MSI script installer. And get the language ID to use from registry.

Dear batch script experts, any improvments welcome.

Edited by Bilou_Gateux, 23 February 2006 - 07:59 AM.

OS Version = 5.1.2600 Service Pack 3
Platform ID = 2 (NT)
Service Pack = 3.0
Suite = 0x0140
Product Type = 1
Architecture = x86

#18
ndog

ndog
  • Member
  • 7 posts
  • OS:none specified
  • Country: Country Flag
Change CD-ROM letter to e: with diskpart

Just cause the above instructions are useless for me

ROM2E.cmd
echo Change -ROM to e: (free up D:)
for /f "tokens=2-3" %%a in ('echo list volume ^| diskpart ^| find "-ROM "') do (
	set _vol=%%a
	rem set _optical=%%b: (this can be used if needed)
	)

echo select volume %_vol% > %temp%\free.txt
echo assign letter=e >> %temp%\free.txt

	diskpart /s %temp%\free.txt
	del %temp%\free.txt

Edited by ndog, 24 May 2011 - 06:18 PM.


#19
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,374 posts
  • OS:none specified
  • Country: Country Flag

Change CD-ROM letter to e: with diskpart

Just for your interest, it is possible to avoid the temporary file.

See here:
http://www.msfn.org/...m-drive-letter/
http://www.msfn.org/...ic=126069&st=19

But in your case you need to add a number of lines, one for each possible drive letter the initial FOR /F may get

jaclaz

Edited by jaclaz, 25 May 2011 - 03:37 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN