Login | |
|
 |
I need a script to change the CDROM drive letter - 5/11/2005 9:34:01 AM
|
|
 |
|
| |
lucdesaulniers
Posts: 10
Score: 0
Joined: 5/11/2005
From:
Status: offline
|
Hi, I have a script that changes my cd-rom drive from d: to f: but it requires a reboot to be effective. Does ne1 know if it is possible to make it effective right away without rebooting the computer? Here is the script. 'Begining of script. ' 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("D:", "F:") 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
|
|
| |
|
|
|
 |
Re: I need a script to change the CDROM drive letter - 5/11/2005 3:10:25 PM
|
|
 |
|
| |
TNO
Posts: 1072
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Someone correct me if I'm wrong, but I think only Logical Drives can be renamed without having to reboot.
|
|
| |
|
|
|
 |
Re: I need a script to change the CDROM drive letter - 5/12/2005 1:50:59 AM
|
|
 |
|
| |
TNO
Posts: 1072
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Maybe this will help: http://support.microsoft.com/kb/300415/
|
|
| |
|
|
|
 |
Re: I need a script to change the CDROM drive letter - 5/12/2005 2:58:02 AM
|
|
 |
|
| |
TNO
Posts: 1072
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
"Why would we be able to change it through Disk management without reboot then?" If that is the case could you not use the SendKeys Method to do it?
|
|
| |
|
|
|
 |
Re: I need a script to change the CDROM drive letter - 5/13/2005 4:26:37 PM
|
|
 |
|
| |
TNO
Posts: 1072
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
That code is the first thing that was posted. It was already said that you still need to reboot.
|
|
| |
|
|
|
 |
RE: Re: I need a script to change the CDROM drive letter - 7/14/2007 9:24:53 AM
|
|
 |
|
| |
timdawg
Posts: 1
Score: 0
Joined: 7/14/2007
Status: offline
|
Excellent idea lucdesaulniers, however, I took it a little further. To ensure that adding or changing devices doesn't mess with the volume numbers, I wrote a script that makes sure a specific Device ID gets a specific Drive Letter. If the Drive letter is not correct, it writes the diskpart script, executes diskpart, then deletes the file it just created, and goes on to the next drive. Here it is: =====Script Start===== On Error Resume Next 'Device IDs DeviceID_V = "" DeviceID_W = "" DeviceID_X = "" DeviceID_Y = "" DeviceID_Z = "" strComputer = "." Dim nRtn, WshShell Set WshShell = WScript.CreateObject("WScript.Shell") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive") For Each objItem in colItems Select Case (objItem.DeviceID) Case DeviceID_V x = ChgDrv ("V:", objItem.Drive) Case DeviceID_W x = ChgDrv ("W:", objItem.Drive) Case DeviceID_X x = ChgDrv ("X:", objItem.Drive) Case DeviceID_Y x = ChgDrv ("Y:", objItem.Drive) Case DeviceID_Z x = ChgDrv ("Z:", objItem.Drive) End Select Next Function ChgDrv(Drive, theDrive) wscript.echo theDrive & " => " & Drive If theDrive <> Drive Then 'Create File strFilename = "C:\Scripts\cdrom\chgdrv" & Left(Drive,1) & ".txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile(strFilename) objFile.Close 'Write Data to File Set objFile = objFSO.OpenTextFile (strFilename, 2) objFile.WriteLine "select volume " & theDrive objFile.WriteLine "assign letter=" & Drive objFile.WriteLine "exit" objFile.Close 'Run Diskpart calling the script just created strRun = "diskpart /s " & strFilename nRtn = wshShell.Run(strRun, 2 , True) 'Delete File objFSO.DeleteFile(strFilename) End If End Function =====Script End===== Don't forget to insert your Device IDs.
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|