Created
August 24, 2017 13:49
-
-
Save mkorthof/deef752e03305a16e46f0e179b036820 to your computer and use it in GitHub Desktop.
VirtualBox savestate all running VM's (Windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: https://superuser.com/questions/959567/virtualbox-windows-graceful-shutdown-of-guests-on-host-shutdown | |
SET "LOG=0" | |
SET "LOGFILE=%~dp0%vboxsave.log" | |
SET VBoxManage="%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe" | |
IF "%~1"=="LOG" ( SET "LOG=1" ) | |
IF EXIST "%LOGFILE%.tmp" ( del %LOGFILE%.tmp ) | |
IF %LOG% EQU 1 ( CALL :msg logging is enabled ) | |
CALL :msg starting %VBoxManage% list runningvms... | |
FOR /F tokens^=2^,4^ delims^=^" %%p IN ('%VBoxManage% list runningvms') DO ( | |
CALL :msg running controlvm %%p savestate: | |
%VBoxManage% controlvm %%p savestate >%LOGFILE%.tmp 2>&1 | |
) | |
IF EXIST "%LOGFILE%.tmp" ( | |
type %LOGFILE%.tmp | |
IF %LOG% EQU 1 ( type %LOGFILE%.tmp >> %LOGFILE% ) | |
del %LOGFILE%.tmp | |
) | |
CALL :msg done | |
GOTO :EOF | |
:msg | |
FOR /f "delims=" %%# IN ('powershell.exe Get-Date -Format G') do @set cdate=%%# | |
echo %cdate% %* | |
IF %LOG% EQU 1 ( echo %cdate% %* >> %LOGFILE% ) | |
GOTO :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment