Windows Server 2008
--
Questions
--
Followers
Top Experts
script to change DVD Drive letter
Hi,
I need a script to change a DVD Drive letter to R: in multiple servers. we have windows 2008 and windows 2003 servers. script should find DVD Drive and then change its letter to R:
In some of the servers we have D: and E: letters for DVD Drive and need to change them to R:
Thanks
Izhar
I need a script to change a DVD Drive letter to R: in multiple servers. we have windows 2008 and windows 2003 servers. script should find DVD Drive and then change its letter to R:
In some of the servers we have D: and E: letters for DVD Drive and need to change them to R:
Thanks
Izhar
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Hi, if you have a test server, run this code on that first, but it should work. Â It uses WMI to identify drives with a DriveType of 5 (Compact Disc), and changes the letter to R:
This runs locally only, it does not run remotely, because the only way (or at least the most reliable way) to change the drive letter was to use the local MountVol utility.
You could run it remotely using PSExec though.
Regards,
Rob.
This runs locally only, it does not run remotely, because the only way (or at least the most reliable way) to change the drive letter was to use the local MountVol utility.
You could run it remotely using PSExec though.
Regards,
Rob.
ChangeDriveLetters
Sub ChangeDriveLetters
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType=5")
For Each objDisk in colVolumes
If objDisk.DeviceID <> "R:" Then ChangeDriveLetterWithMountvol objDisk.DeviceID, "R:"
Next
End Sub
' Change the drive in one drive letter to another drive letter using
' mountvol.exe tool
'
Sub ChangeDriveLetterWithMountvol(strSourceDrive, strTargetDrive)
Dim objShell, objExec
Dim strVolume
Set objShell = CreateObject("WScript.Shell")
' Get volume associated to the old drive letter.
'
Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /L")
strVolume = Trim(objExec.StdOut.ReadLine())
While objExec.Status = 0
WScript.Sleep(100)
Wend
' Unmount the drive.
'
Set objExec = objShell.Exec("mountvol " & strSourceDrive & " /D")
While objExec.Status = 0
WScript.Sleep(100)
Wend
' Mount the drive on the new drive letter.
'
Set objExec = objShell.Exec("mountvol " & strTargetDrive & " " & strVolume)
While objExec.Status = 0
WScript.Sleep(100)
Wend
End Sub
Hi Rob,
I tried this script but its not working.
Thanks
Izhar
I tried this script but its not working.
Thanks
Izhar






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Windows Server 2008
--
Questions
--
Followers
Top Experts
Windows Server 2008 and Windows Server 2008 R2, based on the Microsoft Vista codebase, is the last 32-bit server operating system released by Microsoft. It has a number of versions, including including Foundation, Standard, Enterprise, Datacenter, Web, HPC Server, Itanium and Storage; new features included server core installation and Hyper-V.