Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VirtualBox savestate all running VM's (Windows)
@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
You can’t perform that action at this time.