WIndows でログオフ時にVMWare workstation 上で稼働中のVMをサスペンドさせるスクリプト。
以下の vmsuspend.bat をグループポリシーのログオフスクリプトに仕込めば、ログオフ時にVMを自動的にサスペンドさせられる”はず”
vmsuspend.bat
cscript /nologo vmsuspend.vbs
vmsuspend.vbs
Dim WshShell, oExec
Dim sVmrunCmd, sGetListParam, sStopVmParam, sStopVmOption
Dim sVmVmx
sVmrunCmd = """C:Program Files (x86)VMwareVMware Workstationvmrun.exe"""
sGetListParam = " list"
sStopVmParam = " -T ws suspend "
sStopVmOption = " hard"
Set WshShell = CreateObject("WScript.Shell")
' Get Active VM List
Set oExec = WshShell.Exec(sVmrunCmd & sGetListParam)
Do While oExec.Status = 0
WScript.Sleep 20
Loop
Do Until oExec.StdOut.AtEndOfLine
sVmVmx = oExec.StdOut.ReadLine
if InStr(1, LCase(sVmVmx), ".vmx") > 0 then
Call WshShell.Run(sVmrunCmd & sStopVmParam & sVmVmx & sStopVmOption, 2, true)
end if
Loop