How to know if VirtualBox is installed using APIs

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
AdityaM
Posts: 31
Joined: 8. Nov 2016, 06:12

How to know if VirtualBox is installed using APIs

Post by AdityaM »

Hello,
Is there a way to know if VirtualBox is installed on a particular machine or not? What will happen if I try to use VirtualBox APIs on a system where VirtualBox is not installed? For example if I have an application which uses VirtualBox APIs in the background and hence for that application to run, we have to install the VirtualBox, but what if the VirtualBox is not installed on that machine.
With regards to getting/checking which version of VirtualBox is there, we have an API IVirtualBox::ger_version(), so that can be managed.

Even if I try to look for Oracle installation in C:/> (or default drive) it might be possible that it is not installed in default drive but elsewhere.

Any suggestion on this would be appreciated.

Thanks
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to know if VirtualBox is installed using APIs

Post by noteirak »

All the the following only apply to official builds of VirtualBox. If you're dealing with a custom/OSE build, then all bets are off.

On Windows: There should be at least one of the two environment variables:
  • VBOX_INSTALL_PATH
  • VBOX_MSI_INSTALL_PATH
On Linux, You can:
  • check for the existence of the virtualbox driver, located at /dev/vboxdrv
  • Check for symlinks to the virtualbox executables in the PATH, or simply check if well-knowns executable exists in /usr/lib/virtualbox, like VirtualBox, VBoxManage, vboxwebsrv
On OSX, check for VirtualBox executable in /usr/local/bin

If you want to check for the VirtualBox version before loading any API files, you can always run the following command and read its stdout, which will give you the API version to use on the first line (at the time of writting)

Code: Select all

vboxmanage list systemproperties
As for the question of what happens if you try to use the VirtualBox API if it's not installed - you'll simply get an error saying the library can't be loaded (if you use COM) or a connection refused/timeout (if you use WebServices)
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
AdityaM
Posts: 31
Joined: 8. Nov 2016, 06:12

Re: How to know if VirtualBox is installed using APIs

Post by AdityaM »

Hello,
With the suggested environment variables on windows, I am able to get the information if the Virtualbox is installed or not, but there is one issue, that these variables (or one of these variables) are updated only after the system restart. So for instance, if the VirtualBox was freshly installed on PC, then these variables are not updated/set immediately, but after the PC reboot. Similarly if I uninstall the Virtualbox, the values of these variables is not reset to NULL unless the PC is rebooted.

Also is it recommended/suggested to use the Virtualbox APIs without restarting the host machine, could there be some problems while using the Virtualbox APIs if the host PC/system/machine is not rebooted after the Virtualbox install/uninstall? If no, then what is the better way to understand if the Virtualbox is installed on host system.

I was thinking of a very crude way, to check for the EXE of Virtualbox, as a method to understand if it is installed on the host system or not. Since my development requirement is restricted only to Windows based OS for now. And I can restrict user to always install the Virtualbox on the OS (normally C:) drive.
Would it be the recommended way?

Thanks in advance
-Aditya Mittal
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to know if VirtualBox is installed using APIs

Post by noteirak »

Because VirtualBox goes deep into the system during install (system drivers), restart is an expected step. I believe so far you can get away without it on recent Windows versions, but it's nonetheless not recommended.

Another way to check for install would be looking for the registry key for VirtualBox under the Uninstall section (the part that makes stuff appear in Add/Remove programs) which should only be there while VirtualBox is installed. Beware that can be influenced if the VirtualBox installer is repackaged or modified (since it's a MSI).

Just checking the exe is, as you say, crude but can be effective. Up to you, that really depends how your whole infrastructure is set up.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply