Skip to content

Commit 6533c38

Browse files
committed
Import VirtualBox scripts.
1 parent e7fdc76 commit 6533c38

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

VirtualBox/VMSnapStartGuest.cmd

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@echo off
2+
rem Usage: Place VMSnapStartGuest into the autostart folder of the VM.
3+
4+
rem See corresponding VMSnapStartHost.
5+
6+
rem Basic VBoxControl command used
7+
set vbgp=vboxcontrol --nologo guestproperty
8+
rem Preset error msg for easier if/goto handling
9+
set emsg=
10+
11+
%vbgp% get SnapStart
12+
if errorlevel 1 goto warning
13+
14+
rem See bug description in VMSnapStartHost
15+
set emsg=guestproperty unset command failed.
16+
%vbgp% unset SnapStart
17+
if errorlevel 1 goto failed
18+
goto fini
19+
20+
:failed
21+
echo.
22+
echo ***ERROR*** %emsg%
23+
echo.
24+
pause
25+
goto fini
26+
27+
:warning
28+
echo.
29+
echo ***WARNING***
30+
echo.
31+
echo The VM has not been started via script.
32+
echo.
33+
echo An automatic snapshot has not been taken!
34+
echo.
35+
pause
36+
goto fini
37+
38+
:fini

VirtualBox/VMSnapStartHost.cmd

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@echo off
2+
3+
rem Usage: VMSnapStartHost <vm uuid>
4+
5+
rem - Takes a snapshot of the powered off VM to mitigate crashes.
6+
rem - Unplugs the network cable on adapter 1 for security.
7+
rem - Starts the VM.
8+
rem - Sets the transient guest property SnapStart=1.
9+
10+
rem VirtualBox v6.1.16
11+
rem An autostart guest script (see VMSnapStartGuest) can query the property
12+
rem via VBoxControl and alert the user if it's missing.
13+
rem *BUG* Transient properties should be automatically deleted when the VM
14+
rem shuts down, but somehow that doesn't happen. Therefore the guest script
15+
rem should explicitly unset it (Only VBoxControl...unset seems to work, even
16+
rem VBoxControl...delete has the variable somehow comming back).
17+
18+
rem VirtualBox v6.1.18
19+
rem It seems, the property now survives a restart of the guest OS.
20+
rem The property is removed on VM shutdown. Still using "unset". Not yet tested
21+
rem if "delete" would work now.
22+
rem Seems to have been a glitch, gone again after restart.
23+
24+
25+
rem Unlike other path vars, this one already has trailing backslash.
26+
set vbm="%VBOX_MSI_INSTALL_PATH%vboxmanage.exe" --nologo
27+
28+
rem Preset error msg for easier if/goto handling
29+
set emsg=Missing VM uuid parameter.
30+
if "%1" == "" goto failed
31+
32+
set emsg=The VM is not powered off.
33+
%vbm% showvminfo %1 | find "State:" | find "powered off"
34+
if errorlevel 1 goto failed
35+
36+
set emsg=snapshot command failed.
37+
%vbm% snapshot %1 take "Starting VM"
38+
if errorlevel 1 goto failed
39+
40+
set emsg=modifyvm command failed.
41+
%vbm% modifyvm %1 --cableconnected1 off
42+
if errorlevel 1 goto failed
43+
44+
set emsg=startvm command failed.
45+
%vbm% startvm %1
46+
if errorlevel 1 goto failed
47+
48+
set emsg=guestproperty command failed.
49+
%vbm% guestproperty set %1 SnapStart 1 --flags TRANSIENT
50+
if errorlevel 1 goto failed
51+
goto fini
52+
53+
:failed
54+
echo.
55+
echo ***ERROR*** while starting the VM!
56+
echo.
57+
echo %emsg%
58+
echo.
59+
pause
60+
goto fini
61+
62+
:fini

0 commit comments

Comments
 (0)