0

我想在来宾自定义中运行以下脚本,因此当我从模板部署 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"
4

1 回答 1

0

要在重新启动后运行,您可以确保脚本在任务调度程序中设置一次性任务以运行单行命令。(任务甚至可以设置运行后删除自己)

于 2013-08-22T13:19:33.670 回答