Creating Virtualbox Screenshots with VBoxManage

As a system admin by day I am always documenting how something was done so that others can do it themselves and also as a blogger as well. Text is wonderful but sometimes pictures are much better at explaining.

With Windows and Linux there are many point and click solutions like Snipping Tool (Windows 7), KSnapshot (KDE) and many others, but sometimes the command line is better and can be scripted.

One such documentation task I recently completed was relying heavily on Virtualbox and what I was needing was the whole screen and not a cropped image. Luckily the VBoxManage command includes a parameter controlvm (screenshotpng) to accomplish such a task.

The syntax is:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "" screenshotpng 

As an example mhlinux3 is the name of my vm and test1.png for the filename. So the command will look like

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "mhlinux3" screenshotpng c:\temp\test1.png

Pretty simple. So now lets automate it and create a command script that prompts for a filename. We can use the set command to define the variables and set /P to prompt for the filename.

For the variables we need to set the filename, the vboxmanage command, the output directory and the vm. For the output directory I have created a screenshots folder on the desktop. Below is the script which is saved as vmsnap.cmd on the desktop.

echo off
rem Create Virtualbox screenshots on windows
rem Prompt for filename
set /P ssname="Enter filename: " %=%
set vboxmanage="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"

rem Specify the output directory
set outputdir=%USERPROFILE%\Desktop\screenshots

rem Specify the name of the VM here of which you want to take a screenshot
set vm=mhlinux3

%vboxmanage% controlvm "%vm%" screenshotpng %outputdir%\%vm%_%ssname%.png

If we double-click on the saved script a command box will appear waiting for a filename.

Enter in the name and press enter and the snapshot will complete and the window will close and if we check in the folder we will see the finished product.

And if we open the screenshot we see the finished product.

Happy snapping !!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.