Question : Script to change CD-Rom drive letter

I need a scipt to automatically change the drive letter of my CD/DVD ROM without having to reboot.  It has to be good for either 1, 2, or 3 drves present when I run the script and assign them to X, Y, Z.  The solution also has to be good for both Win XP and Win 7.  It can either be in DOS batch or VBS.

Answer : Script to change CD-Rom drive letter

Yes I did, thanks.

I mades the changes to get it to work with the temp folder variables and have it easier to input new drive letters for those who don't read code very well.

I can't write on the c:\ so the variables make a good alternative.  Thanks a lot for both of your help, it is much appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
@echo off
setlocal enabledelayedexpansion

REM Set your New Drive Letter
set Ndrive1=X
set Ndrive2=Y
set Ndrive3=Z

if exist %tmp%\cdrtmp del %tmp%\cdrtmp
if exist %tmp%\cdrtmp2 del %tmp%\cdrtmp2
if exist %tmp%\romstr del %tmp%\romstr
if exist %tmp%\cdrquer del %tmp%\cdrquer
echo.list volume>%tmp%\cdrquer
diskpart /s %tmp%\cdrquer>%tmp%\cdrtmp
findstr /i "CD-ROM" %tmp%\cdrtmp>>%tmp%\romstr
findstr /i "DVD-ROM" %tmp%\cdrtmp>>%tmp%\romstr
set /a line=1
for /f "tokens=1,2,3" %%a in (%tmp%\romstr) do (
	if !line!==1 (
		echo.select %%a %%b>>%tmp%\cdrtmp2
		echo.assign letter=%Ndrive1%>>%tmp%\cdrtmp2
	)
	if !line!==2 (
		echo.select %%a %%b>>%tmp%\cdrtmp2
		echo.assign letter=%Ndrive2%>>%tmp%\cdrtmp2
	)
	if !line!==3 (
		echo.select %%a %%b>>%tmp%\cdrtmp2
		echo.assign letter=%Ndrive3%>>%tmp%\cdrtmp2
	)			
	set /a line=!line!+1
)


if exist %tmp%\cdrtmp2 diskpart /s %tmp%\cdrtmp2>nul
if exist %tmp%\cdrtmp del %tmp%\cdrtmp
if exist %tmp%\cdrtmp2 del %tmp%\cdrtmp2
if exist %tmp%\romstr del %tmp%\romstr
if exist %tmp%\cdrquer del %tmp%\cdrquer
Random Solutions  
 
programming4us programming4us