我想在客户端自定义中运行以下脚本,因此当我从模板部署VM时,Windows卷具有正确的驱动器号。下面的脚本工作但需要重新启动,重新启动后我想调用我的SQL安装命令,该命令当前只是.cmd文件中的一行。任何人都可以帮我添加一个等待命令到驱动器号脚本,然后重启后调用cmd吗?
使用PowerShell还有一种更简单的方法吗?
CMD File;
cd c:
C:\Setup\SQL2008R2_SP2\Setup.exe /CONFIGURATIONFILE=C:\Setup\SQL2008R2.ini /INDICATEPROGRESS
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
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
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
答案 0 :(得分:0)
要在重新启动后运行,您可以确保脚本在task-scheduler中设置一次性任务以运行one line命令。 (任务甚至可以设置为在运行后删除自己)