VB Script that changes the CDROM drive letter Print
Written by Winfred DeKreij   

'
'    Script creates a local file that gets called by Diskpart to change the CDROM drive to Z:
'
'    

 

strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set fso = CreateObject ("Scripting.FileSystemObject")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

'define the path where the file was started
ScriptStartLocation = left(Wscript.ScriptFullName, ((instr((Wscript.ScriptFullName), (wscript.ScriptName)))-1))


'Select CDROM drive (here you select drive letter you want it renamed to)
For Each objItem in colItems

    If fso.DriveExists("Z") = False Then
        Errcode = ChgDrv("Z:", objItem.Drive)
    end if
Next

'======================================================
'
'Function changes CDROM drive letter.
'
'======================================================
Function ChgDrv(Drive, theDrive)
wscript.echo theDrive & " => " & Drive
If theDrive <> Drive Then

     'Create File
     strFilename = ScriptStartLocation & "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

Add your comment

Your name:
Your website:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification: