Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
Kalz

Change CD-Rom Drive letter for unattended XP

Recommended Posts

Hi

I am wanting to change the drive letter of my CD-Rom drive from the Default. I have 2 partitions on my Hard Disk which are automatically assigned to Drive C: and Drive D: By default Win XP assigns the next letter (E:) to my CD-Rom but during unattended setup I would like to assign the letter X: to my CD-Rom.

I know I could do this after setup has finished form computer management but I am wanting to do this with no user input.

If anyone knows how to do this or even if it is possible or not your help would be very much appriciated.

Thanks in advance, Kal ...

Edited by Kalz

Share this post


Link to post
Share on other sites

Here a vbs script that will change the Cd drive letter

strComputer = "."
Change_CD_Letter
Function Change_CD_Letter
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume Where Name = '" & CD & "\\'")
For Each objVolume in colVolumes
objVolume.DriveLetter = "PLACE_YOUR_DRIVE_LETTER_HERE"
objVolume.Put_
Next
Exit Function
End Function

Share this post


Link to post
Share on other sites

Hi Gunsmokingman

Where would I put this VB Script? Will I need to create my own application and run it as soon as XP is installed and then run the once run to install other applications?

Please help, Kal ...

Share this post


Link to post
Share on other sites

Here is the full script I was tired when I first posted and tried to make it smaller, I have only tested this on Vista, and it works. I have not test this on any other OS.

strComputer = "."
Dim Act, Fso, CD, SearchString, SearchChar, MyPos, ChangeDrv, SD
Set Act = CreateObject("Wscript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
SD = Act.ExpandEnvironmentStrings("%Systemdrive%")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
'''' GET THE CDROM DRIVE LETTER
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CD_Get_Drive
For Each objItem in colItems
SearchString = objItem.Caption
MyPos = Instr(1, SearchString, "RW")
CD = objItem.Drive
If MyPos = 1 Then
MsgBox "This Is Not A CD-RW", 0 + 32, "Not A CD-RW"
Exit Function
Else
SearchChar = "Caption: " & objItem.Caption & vbCrLf & "Name: " & objItem.Name & vbCrLf & CD
Act.Popup SearchChar, 5, "Confirm CD-RW",0 + 32
Change_CD_Letter
Exit For
End If
Next
End Function
'''' CHANGE DRIVE LETTER HERE
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Change_CD_Letter
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume Where Name = '" & CD & "\\'")
For Each objVolume in colVolumes
ChangeDrv = InputBox("Please type in the new drive letter you would like to assign to the drive" &_
vbCrLf & "The current Drive Letter Is : " & CD & vbcrlf & "Example Z: or Y:","Change Drive" )
objVolume.DriveLetter = "" & ChangeDrv & ""
objVolume.Put_
Next
Exit Function
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
CD_Get_Drive
Act.Popup "Completed CD Drive Letter Change" & vbCrLf & "Old CD Drive Letter : " & CD &_
vbCrLf & "New CD Drive Letter : " & ChangeDrv, 7,"Finished", 0 + 32
If Fso.FileExists(SD & "\ChangeCD_Letter.vbs") Then : Fso.DeleteFile(SD & "\ChangeCD_Letter.vbs") : End If

Run it before the RunOnceEx.cmd is processed in a Ua Install, because if you run it after the RunOnceEx.cmd

it may produce a error.

Example Only

[COMMANDS]

"ChangeCD_Letter.exe"

"UserAcount.cmd"

"RunOnceEx.cmd"

Edited by gunsmokingman

Share this post


Link to post
Share on other sites

Hi Gunsmokingman

Thanks for compling the application for me. When I run the app I get an WINDOWS SCRIPT Host error (see Screenshot). Any suggestion?

Thanks again, Kal

Edited by Kalz

Share this post


Link to post
Share on other sites

There no screen shots for me to see.

Here is what I get when I run it.

Edited by gunsmokingman

Share this post


Link to post
Share on other sites

1) I always do this after install, too, but it would be better during install since I have to reassociate the install paths (e.g., OS installed from D, I change it to Z, but rhe registry still says the install source is D): just to verify, though, will this solve this problem--or will I have to still change the registry? In other words, is the regsitry path written BEFORE the vbscript runs?

2) Is it possible to have a script that would change TWO optical drives to, for instance, Y and Z (master and slave)? (Since I almost always have two drives in the systems I build, this would be, of course, more ideal.)

3) What about changing logical partition letters/names?

Thanks

Edited by nowinscenario

Share this post


Link to post
Share on other sites
1) I always do this after install, too, but it would be better during install since I have to reassociate the install paths (e.g., OS installed from D, I change it to Z, but rhe registry still says the install source is D): just to verify, though, will this solve this problem--or will I have to still change the registry? In other words, is the regsitry path written BEFORE the vbscript runs?

2) Is it possible to have a script that would change TWO optical drives to, for instance, Y and Z (master and slave)? (Since I almost always have two drives in the systems I build, this would be, of course, more ideal.)

3) What about changing logical partition letters/names?

Thanks

1:\ On Vista it show the change drive letter in Explorer after the script runs.

2:\ Yes it possible

3:\ Yes it possible

Kalz

Just cut and paste the second script I post and save as a file with a VBS extention, then try it, as I said I have only tested this script on Vista, and have not tested it on any other OS. So I do not know what it runs like on XP W2K W3K. I write scripts to see if I can crash Vista so that what that script was for originally for.

It just one of the ways I test Vista.

Share this post


Link to post
Share on other sites

Hi

It keeps returning the 'Windows Script Host' error in line 31, just before asking what to change the drive letter to. This line is where the error is:

For Each objVolume in colVolumes

could it be the variables are not supported in XP?

Also, is it possible to change the CD-Rom Drive Letter in the Windows PE environment before installation begins?

Any help would be much appriciated.

Kalz ...

Edited by Kalz

Share this post


Link to post
Share on other sites

I have now tested the script on XP I do not get the erorrs, but it does not seem to change the drive letter.

Who would think that a VBS script, works on Vista but not XP. I will see if I can fix it so it works on XP.

Share this post


Link to post
Share on other sites

Here is an example batch file for Windows XP.

It changes the last found CD-ROM drive letter to one of your choice.

To run it enter

  • CDNowTo x

where x is the drive letter you require and CDNowTo is the name of the batch file

I have commented it for you to understand how it works, since I will not be making requested changes to it.

CDNowTo.cmd:

@ECHO OFF &SETLOCAL ENABLEEXTENSIONS

::Set window parameters
MODE 49,4 &COLOR F2 &TITLE Script By Yz”wl

:: Set variable for required Drive Letter, quit if not given
SET "INP=%*"
IF NOT DEFINED INP GOTO ENDIT
SET "INP=%INP:~0,1%"

:: Quit if INPut drive letter already exists
MOUNTVOL |FIND "%INP%:\" >NUL 2>&1 &&GOTO ENDIT

:: Get last CD Drive letter
FOR /F %%? IN ('MOUNTVOL ^|FIND ":\" ^|FIND /I /V "A:\"') DO (FSUTIL FSINFO DRIVETYPE %%? |FIND /I "CD-ROM" >NUL 2>&1 &&SET CDROM=%%?)

:: Quit if CDROM does not exist
IF NOT DEFINED CDROM GOTO ENDIT

:: Quit if CDROM is already INPut drive
IF /I "%CDROM%" EQU "%INP%:\" GOTO ENDIT

:: Ensure upper case variable for INPut drive
FOR /F "TOKENS=4 DELIMS=? " %%? IN ('FC ?%INP% : 2^>^&1') DO CALL SET "NEWDRIVE=%%NEWDRIVE%%%%?:"

:: Set variables for registry key and value names
SET "REGKEY=HKLM\SYSTEM\MountedDevices"
SET OLDVALNAME="\DosDevices\%CDROM:~0,2%"
SET NEWVALNAME="\DosDevices\%NEWDRIVE%"

:: Query existing registry data
FOR /F "SKIP=1 TOKENS=3 DELIMS= " %%? IN ('REG QUERY %REGKEY% /V %OLDVALNAME%') DO (SET DATA="%%?")

:: Add new registry information, quit if unsuccessful
REG ADD %REGKEY% /V %NEWVALNAME% /T REG_BINARY /D %DATA% >NUL 2>&1 ||GOTO ENDIT

:: Delete old registry information
REG DELETE %REGKEY% /V %OLDVALNAME% /F >NUL

:: give a message to the user for 10 seconds
ECHO/&ECHO/ CD-ROM drive letter changed from %CDROM:~0,2% to %NEWDRIVE%
ECHO/&ECHO/ For the changes to take effect PLEASE REBOOT...
PING -n 11 LOCALHOST>NUL

:ENDIT
ENDLOCAL &GOTO :EOF

On line 32 DELIMS=<TAB>

Share this post


Link to post
Share on other sites

My two cents worth ...

(Sorry for the cut and paste, Yzöwl, but you said it so clear ...)

This changes the first four CD / DVD Drive letters to those of your choice.

To run it enter:

SETCD K: L: M: N:

where K: L: M: and N: are the drive letters you require, and SETCD is the name of the batch file.

I have commented it for you to understand how it works, since I will not be making requested changes to it.

SETCD.CMD:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

SET LOGFILE=%SYSTEMROOT%\XPCSETUP.TXT
SET LOGLINE=-------------------------------------------------------------------------------

ECHO %LOGLINE% >> %LOGFILE%
ECHO -- %TIME:~0,8% -- Starting SETCD >> %LOGFILE%
ECHO %LOGLINE% >> %LOGFILE%

:: This version of SETCD is for Windows XP SP2.
:: It will change the CD Drive Letters, the Installation Source value,
:: and create a System Variable INSTALLCD, used for subsequent applications.

:: Find out which CD is listed as Install Source
FOR /F "TOKENS=3" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "SourcePath" ^| FINDSTR "SourcePath"') DO SET INSTCD=%%~dI

:: Get any passed parameters
SET NEWCDROM1=%1
SET NEWCDROM2=%2
SET NEWCDROM3=%3
SET NEWCDROM4=%4

:: If we were not passed new drive letters, use these:
IF "%NEWCDROM1%"=="" SET NEWCDROM1=K:
IF "%NEWCDROM2%"=="" SET NEWCDROM2=L:
IF "%NEWCDROM3%"=="" SET NEWCDROM3=M:
IF "%NEWCDROM4%"=="" SET NEWCDROM4=N:

ECHO %LOGLINE% >> %LOGFILE%
ECHO SETCD Log File >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO Install CD = %INSTCD% >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO NEWCDROM1 = %NEWCDROM1% >> %LOGFILE%
ECHO NEWCDROM2 = %NEWCDROM2% >> %LOGFILE%
ECHO NEWCDROM3 = %NEWCDROM3% >> %LOGFILE%
ECHO NEWCDROM4 = %NEWCDROM4% >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO DOS Devices as per Registry: >> %LOGFILE%
ECHO. >> %LOGFILE%
REG QUERY HKLM\SYSTEM\MountedDevices | FINDSTR "DosDevices" >> %LOGFILE%

SET NEWINSTCD=
SET CDCOUNT=0

:: Loop throgh list of DOS Devices:
FOR /F "TOKENS=1,2,3 DELIMS= " %%A IN ('REG QUERY HKLM\SYSTEM\MountedDevices ^| FINDSTR "DosDevices"') DO (
SET RAWRESULT=%%A
SET RESULT=!RAWRESULT:~26,18!
:: CDs are encoded as "5C003F003F005C0049"
IF "!RESULT!"=="5C003F003F005C0049" (
SET DLETTER=!RAWRESULT:~12,2!
SET /A CDCOUNT=!CDCOUNT!+1
:: Get current drive letters into CDROMn variables.
IF "!CDCOUNT!"=="1" SET CDROM1=!DLETTER!
IF "!CDCOUNT!"=="2" SET CDROM2=!DLETTER!
IF "!CDCOUNT!"=="3" SET CDROM3=!DLETTER!
IF "!CDCOUNT!"=="4" SET CDROM4=!DLETTER!
)
)

ECHO. >> %LOGFILE%
ECHO CDs found: %CDCOUNT% >> %LOGFILE%
ECHO. >> %LOGFILE%
ECHO CDROM1 = %CDROM1% >> %LOGFILE%
ECHO CDROM2 = %CDROM2% >> %LOGFILE%
ECHO CDROM3 = %CDROM3% >> %LOGFILE%
ECHO CDROM4 = %CDROM4% >> %LOGFILE%
ECHO. >> %LOGFILE%

:: Got through CDs found above
:: If we are changing the Install CD letter, update the NEWINSTCD variable
:: Get the Volume Info for each drive, which we need to mount the Volume to new letter.
:: SUBST the old drive letter to new drive, in order to finish installation.
:: Do that for all possible drives (0-4)

IF "%CDROM1%"=="" GOTO NOMORECDS
IF "%CDROM1%"=="%INSTCD%" SET NEWINSTCD=%NEWCDROM1%

ECHO Changing %CDROM1% to %NEWCDROM1% >> %LOGFILE%

FOR /F "TOKENS=1 DELIMS= " %%A IN ('MOUNTVOL %CDROM1% /L') DO SET VOLINFO=%%A
MOUNTVOL %CDROM1% /D
MOUNTVOL %NEWCDROM1% %VOLINFO%
SUBST %CDROM1% %NEWCDROM1%\

IF "%CDROM2%"=="" GOTO NOMORECDS
IF "%CDROM2%"=="%INSTCD%" SET NEWINSTCD=%NEWCDROM2%

ECHO Changing %CDROM2% to %NEWCDROM2% >> %LOGFILE%

FOR /F "TOKENS=1 DELIMS= " %%A IN ('MOUNTVOL %CDROM2% /L') DO SET VOLINFO=%%A
MOUNTVOL %CDROM2% /D
MOUNTVOL %NEWCDROM2% %VOLINFO%
SUBST %CDROM2% %NEWCDROM2%\

IF "%CDROM3%"=="" GOTO NOMORECDS
IF "%CDROM3%"=="%INSTCD%" SET NEWINSTCD=%NEWCDROM3%

ECHO Changing %CDROM3% to %NEWCDROM3% >> %LOGFILE%

FOR /F "TOKENS=1 DELIMS= " %%A IN ('MOUNTVOL %CDROM3% /L') DO SET VOLINFO=%%A
MOUNTVOL %CDROM3% /D
MOUNTVOL %NEWCDROM3% %VOLINFO%
SUBST %CDROM3% %NEWCDROM3%\

IF "%CDROM4%"=="" GOTO NOMORECDS
IF "%CDROM4%"=="%INSTCD%" SET NEWINSTCD=%NEWCDROM4%

ECHO Changing %CDROM4% to %NEWCDROM4% >> %LOGFILE%

FOR /F "TOKENS=1 DELIMS= " %%A IN ('MOUNTVOL %CDROM4% /L') DO SET VOLINFO=%%A
MOUNTVOL %CDROM4% /D
MOUNTVOL %NEWCDROM4% %VOLINFO%
SUBST %CDROM4% %NEWCDROM4%\

:NOMORECDS

:: If we have a New Install CD, update the registry for the Install Source.
:: Also create a system wide Environment Variable that will tell us the Install CD Drive Letter.

IF NOT "%NEWINSTCD%"=="" (
ECHO. >> %LOGFILE%
ECHO Updating SourcePath to %NEWINSTCD%\I386 >> %LOGFILE%
ECHO Creating INSTALLCD Variable = %NEWINSTCD% >> %LOGFILE%
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /V "SourcePath" /T REG_SZ /D %NEWINSTCD%\I386 /F
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V INSTALLCD /T REG_SZ /D %NEWINSTCD% /F
)

ECHO %LOGLINE% >> %LOGFILE%
ECHO -- %TIME:~0,8% -- Finished SETCD >> %LOGFILE%
ECHO %LOGLINE% >> %LOGFILE%

This will change the drive letters to that which you specify, or K:, L: M: and N: by default if no drive letter is passed. The drive letter is changed immediatly, without the need for a reboot. During the Windows Installation, if this is run before setup finishes, this has the adverse effect that the Install CD cannot be found. For this reason, the existing drive letter is also "kept", using a DOS SUBST command. Additionaly, this will update the Windows Registry to reflect the new drive letter in the "Install Source" registry value. Finally, it will create an system variable called INSTALLCD, that can be used to identify the Intall CD Drive in BATCH files at a later date (after the next reboot). This script runs silently, and uses the logfile XPCSETUP.TXT that will be found in the %SYSTEMROOT% directory, usually C:\Windows.

This SETCD.CMD file has been working just fine for me for quite a while, so I, like Yzöwl, will not be making requested changes to it. For information, this does not work for me in Windows 2003 Server: I have a slightly modified verstion for that OS.

Share this post


Link to post
Share on other sites

GreenMachine this works perfectly and although i have not tried it, it should also fixed the issue of the drive letter XP is being installed from. Thanks a lot, I really mean it as it makes my unattended CD 1 step closer to total unattended.

A few question:

1. Where do I put the created cmd file on my CD (I think it would be the OEM folder).

2. At what point do I call the cmd file (I think before RunOnce application & drivers installations).

3. How do I call the cmd file.

thanks, Kal ...

Share this post


Link to post
Share on other sites

1) It depends on how you use it. From CMDLINES.TXT you could put it directly in the $OEM directory. From SVCPACK.INF, it would go in the SVCPACK directory. From GUIRunOnce it can go anywhere, as long as your call to it reflects the correct location.

2) You can call it at about anyponit. I use SVCPACK.INF.

3) SETCD will work fine, if you want K, L, M and N as drive letters. Otherwise, SETCD, followed by one to four new drive letters, each with the ":" after the drive letter.

See the Unattended Guide for adding CMD files to CMDLINES.TXT, SVCPACK.INF or GUIRunOnce.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...