Take the 2-minute tour ×

I would like to run the following script as part of my guest customization so when I deploy a VM from a template, the windows volumes have their correct drive letters. The script below works but requires a reboot, following the reboot I would like to call my SQL setup command which currently is just one line in a .cmd file. Could anyone help me to add a wait command to the drive letters script and then call the cmd after a reboot?

Also is there an easier way with PowerShell?

CMD File;

cd c:

Change Drive Letters (Original source http://imallvirtual.com/?p=482)

' Script that changes drive letters
' Note: Do NOT use it on SYSTEM or BOOT partition drive letters !!!

set objShell = CreateObject("WScript.Shell")
' objShell.Run("regedit /s C:\Setup\MsgBox.reg")

sComputer = "."
Const HKLM = &H80000002

' from/to
If ChangeDrvLetter("D:", "T:") Then
End If

If ChangeDrvLetter("F:", "X:") Then
End If

If ChangeDrvLetter("G:", "D:") Then
End If

Function ChangeDrvLetter(sSourceDrive, sTargetDrive)
 bOK = True ' Init value
 & 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
 bOK = False
 End If
 bOK = False
 End If
 ChangeDrvLetter = bOK
End Function
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
share|improve this question

1 Answer 1

To run after reboot, you can sure have the script set a one time task in task-scheduler to run the one line command. (the task can even be set to delete himself after running)

share|improve this answer
Thanks for the reply, I have managed to get around the issue by creating a reg key in 'RunOnce' (support.microsoft.com/kb/310593/en-us) Then upon reboot it calls the SQL setup batch file. Thanks anyway :) –  user2704164 Aug 22 '13 at 13:54
I agree with you, the Reg-RunOnce aproech is much more simple. However the Task-scheduler may have more logs if you need. –  ToThePoint Aug 23 '13 at 18:33

Your Answer


