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:

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

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.

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 *