Virtualbox run as service windows

Запускаем виртуальную машину VirtualBox как службу Windows

VirtualBox — это популярный бесплатный гипервизор, производства компании Oracle. Не смотря на то, что сам программный продукт весьма и весьма богат на всевозможные настройки, некоторых важных вещей он сделать не в состоянии. К примеру — запуск виртуальной машины в фоне, как службу Windows. К счастью, для этой цели есть отдельная программа, и в этой статье мы разберем как ей пользоваться.

Использование программы VBoxVmService

Для запуска виртуальных машин под VirtualBox как службы очень удобно использовать программу под названием VBoxVmService, которую скачать можно здесь. После завершения скачивания, устанавливаем программу, в процессе установки по сути ничего, кроме нажатия кнопки «Далее» делать не нужно.

После установки переходим в папку с установленной программой (по умолчанию — C:\vms), открываем там файл VBoxVmService.ini, и начинаем его переделывать под свои нужды. Ниже описаны обязательные для редактирования настройки:

[Settings]
VBOX_USER_HOME
— тут нужно указать путь к папке с виртуальными машинами.

[Vm0]
VmName
— указываем имя виртуальной машины;
ShutdownMethod=savestate — метод завершения работы виртуалной машины, которых может быть два — «savestate» или «acpipowerbutton«. Первый при выключении сохраняет состояние виртуальной машины, и при включении как бы продолжит её работу, второй является как бы полноценным выключением компьютера;
AutoStart — запускать виртуальную машину автоматом, при включении компьютера? Возможные варианты — yes и no, в переводе думаю не нуждаются.

Допустим, если целью стоит запуск виртуальной машины с названием Linux-Debian, то файл настроек будет выглядеть следующим образом:

После окончания редактирования сохраняем файл, запускаем исполняемый файл VBoxVmService.exe с параметром -i , и перезагружаем компьютер.

После этих действий указанная виртуальная машина должна запуститься автоматически.

Virtualbox run as service windows

1. What is VBoxVmService?

VBoxVmService is a Windows Service, that enables the host-system to run or shutdown VirtualBox Virtual Machines (VMs) without a user being logged on to the host-system running Windows (Win10/2012/2016, both x86 and x64 supported).

2. How to use VBoxVmService?

Check the detailed howto guide.

If you run into problem, please follow the TROUBLESHOOTING section in the guide first, most likely your issue has been addressed there. Check for known issues on the wiki before submitting new issue.

3. How does it work?

Basically, VBoxVmService is just a wrapper-service that calls VirtualBox COM API interfaces.

When windows starts up, the wrapper-service will start running. It will check for the settings in VBoxVmService.ini file, and call up the Virtual Machines as specified. Both the wrapper-service and Virtual Machines are run with the account specified in the VBoxVmService.ini file.

If RunWebService=yes is specified in VBoxVmService.ini file, the wrapper-service will also try to start VirtualBox web service automatically. This might be useful for people who use the web service a lot, like users of phpVirtualBox.

When windows shuts down, the wrapper-service will try to stop all the VMs configuered in VBoxVmService.ini.

VmServiceControl.exe is the CLI (command line interface) client that sends control commands to VBoxVmService and display returned results.

VmServiceTray.exe is another client like VmServiceControl.exe, but comes with GUI interface and stays in system tray.

If you are interested in further details, feel free to browse the supplied source codes!

4. What are the plans for the future?

Actually, there are no plans for future releases of this software, other than keeping it updated so that it can always work with latest version of VirtualBox.

5. Which versions of Windows are supported?

Old Windows versions like Windows 7 are no longer supported.

It hasn’t been fully tested on systems other than Windows 10, but it is supposed to work on server systems like Win2012, Win2016, . etc, both 32bit and 64bit versions.

6. Will VBoxVmService run on Mac OS-X or Linux?

No. VBoxVmService is specially designed to suit the Windows operating system. And it doesn’t need to run on Mac OS-X or Linux because these platforms supply adequate features to accomplish the same effect.

First version of VBoxVmService, patching together the C++ code of VBoxVmService and the helper tool «sleep.exe», messing with some c# for «bcompile.exe» plus all the batch-scripting was done by Mathias Herrmann.

Читайте также:  Sg3 utils для windows

Only Fang joined the project in August 2010, and had become main contributor since then. He re-designed the service, added VmServiceControl.exe to do all the controlling job and changed VBoxVmService.exe to become a pure service program.

Runar Buvik joined the project in December 2010, bringing lots of creative improvements like two way communication between the service and control program, new commands to show current VM status and check service environment, etc.

About

Windows Service to run VirtualBox VMs automatically

How to Run a VirtualBox Virtual Machine as a Windows Service with AlwaysUp

Ensure that your VirtualBox VM starts immediately when your PC boots and is available 24/7. No login necessary!

VirtualBox is an free, open-source virtualization platform that can host Windows, Linux, Solaris and other operating systems.

To run your VirtualBox VM with AlwaysUp:

Download and install VirtualBox, if necessary. Be sure to install the VirtualBox extension pack if you intend to use VirtualBox’s Remote Display feature to connect to your VM.

Please make a note of the VirtualBox installation directory (by default, C:\Program Files\Oracle\VirtualBox) as this will be used in subsequent steps.

Next, if necessary, configure your VirtualBox VM for remote access via RDP. Start VirtualBox, highlight your VM in the list and choose Machine > Settings. Select Display on the left and move over to the Remote Display tab. Check the Enable Server box and enter a port number in the Server Port field. We recommend using a number between 7000 and 8000 and we have used 7070 in our setup.

Select Application > Add to open the Add Application window:

On the General tab:

In the Application field, enter the full path to the VBoxHeadless.exe application, which allows you to start a VM without a graphical interface. If you installed VirtualBox in the default location, this is:

In the Arguments field, enter:

Note: VirtualBox user Jesse Connor prefers to start his VM using its unique identifier (UUID). He specifies arguments -s instead, where is the identifier for his VM found by running command Vboxmanage.exe list vms.

In the Name field, enter the name that you will call the application in AlwaysUp. We have used Win8DevPreview VM but you can specify virtually anything you like.

Click over to the Logon tab:

Enter the user name and password of the account in which you installed and run VirtualBox. Your VM will run in this account so that it can find its settings.

Click over to the Startup tab and check the Ensure that the Windows Networking components have started box. This informs AlwaysUp that VirtualBox needs the TCP/IP networking stack to operate.

Move to the Extras tab and:

Check the Use this special command to stop the application box. Specify the full path to the VBoxManage.exe application along with a few arguments:

«C:\Program Files\Oracle\VirtualBox\VBoxManage.exe» controlvm savestate

Note: VirtualBox user Jesse Connor prefers use the ACPI shutdown instead of the recommended savestate because his Linux boxes don’t seem to recover smoothly from saved states. He specifies C:\Program Files\Oracle\VirtualBox\Vboxmanage.exe controlvm acpipowerbutton instead, where is the identifier for his VM found by running command Vboxmanage.exe list vms.

Check the Wait for up to: box and enter 30 in the accompanying field. This informs AlwaysUp to wait for up to 30 seconds for VirtualBox to exit properly before forcibly closing it.

Click the Save button. In a couple of seconds, an application called Win8DevPreview VM will show up in the AlwaysUp window. It is not yet running though.

To start the VirtualBox VM, choose Application > Start «Win8DevPreview VM» (your application name will be different!). After starting, we connected via RDP ( at localhost:7070) to confirm that the VM is running properly.

Note @ 2/21/2016: Even though your VM is running, the VirtualBox Manager window may still show the VM as «Powered Off». We saw this strange behavior when testing VirtualBox Version 5.0.14 r105127. Thankfully the incorrect staus didn’t seem to have any effect on our running VM and we were able to connect to it without a problem.

That’s it! Next time your computer boots, your VirtualBox VM will start up immediately, before anyone logs on. We encourage you to edit your application in AlwaysUp and check out the many other settings that may be appropriate for your environment.

How to run “Oracle VirtualBox (VBOX)” like a service after boot in fully background “Microsoft Windows (WIN)”?

PROBLEM

Читайте также:  Xerox workcentre 3025 linux mint

How can I do that in fully running background process?

8 Answers 8

SOLUTION

The trick is to run the VM without GUI. With this you can easily run VM on WIN server like a service too.

0) Prerequired is that exist some VM, you have some already. Below put its name instead .

1) At first we use build-in executable file «VBoxHeadless.exe».

run and test it — WIN «Command Line Interface (CLI)» called «Command shell» will be open and VM will running in background.

run and test it — CLI will be run in background.

REFERENCES

You can use VBoxManage to start a VM headless:

I used something similar to Samuel’s solution that works great.

On the desktop (or any folder), right click and go to New->Shortcut.

In the target, type:

In the name, type whatever you want and click Finish.

Then to stop the same vm, create a new shortcut with the target being:

Double clicking these starts and stops the VM without any window staying open.

Starting from VirtualBox 4.2 you can just hold Shift while launching the vm to run it fully in background. See details here.

It works perfect for me !

If you do not mind operating the application once manually, to end with OS running in background; here are the options:

Open Virtual Box. Right Click on your Guest OS > Choose: Start Headless. Wait for a while till the OS boots.

Then close the Virtual Box application.

Following Bruno Garett’s Answer, in my experience: testing the vm.run.bat file fails, gives a read only error but will work fine running the VB script. Just to save anyone time.

Also to shut down headless you can use another batch script (Sam F’s solution wont work with Bruno’s solution):

Second line was obtained from here you can use whichever option you want.

There an easy manual option right in the GUI too:

(Taken from Virtualbox 5.2)

Not the answer you’re looking for? Browse other questions tagged service virtualbox virtualization vbox or ask your own question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

How can I run a VirtualBox machine as a service on Windows XP ?

I have a VirtualBox machine with Windows XP on a Windows XP Host.

How can I start VirtualBox as a service, so I can get a virtual machine under the hood, and I don’t have to start VirtualBox in order to access my virtual machine (via VNC from the network)?

I found that VirtualBox Manage might be the way to go, but since I’m a beginner with this, I don’t know where to start.

6 Answers 6

Create a Shortcut to C:\Program Files\innotek VirtualBox\VBoxManage.exe

After the quotation marks enter: startvm

Copy/Move the shortcut to your startup folder.

p.s.: if you want to delay the Virtual Machine until your system is fully booted, you can do this in XP via Startup Delayer.

Note that the currently accepted answer (Molly7244) actually starts the VM when you login — not when you boot the machine. It is not, in other words, a service.

For an actual service that runs when the machine boots, I use two scripts (originally from here) in conjunction with cygwin (cygrunsrv). Makes use of the VBoxHeadless mode as mentioned elsewhere on this page.

The first script runs your VM via VBoxHeadless; it gets the name of the right VM to run (and other info such as your VBOX home directory) from environment variables. The second script installs a service for a particular VM (by using cygrunsrv to call the first script with the right env. vars set). Finally there’s a third file which contains common functions. If you put all of these into a directory together, you can install a new vm like so:

And then start the service with «net start vboxd-MyVMName» or «cygrunsrv -S vboxd-MyVMName».

Here is the VM-running script, «vboxd»:

And here is the installer script, «vboxd-install»:

And, finally, here is the «.libcommon» script referenced by both of these:

This solution works great for me; hopefully you’ll have similar luck.

Looks like the simplest answer at this point is VBoxVMService. I haven’t tried it yet, I’ll try to remember to come here and update the answer if/when I do.

Agreed on VBoxVMService. It is really easy to set up and seems to be working well. You can find a how to on setting it up here:

Читайте также:  Что такое окно windows названия элементов

****EDIT**** As per the request below, a summary of the link. Although the solution worked for me, the credit goes to Peter Upfold — http://peter.upfold.org.uk/

  • Install Virtualbox and setup the VM to accept RDP sessions.
  • Download and install VBoxVmService into C:\vms. Just Google VBoxVmService for a download link (sorry, not enough rep to post more than 2 links).
  • Edit VBoxVmService’s ini file under C:\vms:

[Vm0] VmName=name of the vm in VirtualBox

Substitute in the VBOX_USER_HOME with the .VirtualBox folder in the correct user’s home directory, as well as the RunAsUser and UserPassword directives, and set the name of the target virtual machine in the VirtualBox app in VmName. You can also add additional [Vmx] sections after [Vm0] with other virtual machines to start when the machine boots.

When you are happy with your configuration, from an Administrator-enabled Command Prompt, run the following command to install the service. Once the service is installed, you can remove your user password from the INI file, as it is saved in the Service configuration:

Now, you must reboot the computer before attempting to start the service for the first time, or it will be unable to locate the VMs.

Upon reboot, the service should start (subject to the ‘Automatic (Delayed Start)’ delay) and your VMs will be started upon boot.

Just offering this as another option:

Use the builtin Windows command ‘sc’ to create a service. Combine this with ‘vboxheadless’ will get you to where you want to be.

Untested with vboxheadless specifically, but I did create a test service that runs calc.exe. You should be doing something like this:

sc create servicenamehere start= auto binPath= «C:\path\to\vboxheadless.exe —startvm name»

Refer to the documentation for sc for more information. Note: Those spaces after the equal sign are intentional.

If the vboxd scripts are giving you as much trouble as they did me, you might want to try this; it’s a rather simpler solution, implemented in Perl, which provides the same functionality. Specifically, the VM starts up with the system (assuming the service is set to start automatically, which is the default), and goes down cleanly when the service is stopped.

Major differences from the vboxd solution, aside from being considerably simpler to deal with in my experience, are that this script doesn’t pass a VRDE port setting to VBoxHeadless, and that the VM shutdown is handled via «acpipowerbutton» rather than «savestate».

If this doesn’t suit your purposes, it’s easy enough to change; in the first case, add ‘-e «TCP/Ports=[,port. ]»‘ to the VBoxHeadless command line string ($cmd), and in the second case, just change «acpipowerbutton» to «savestate» in the SIGTERM handler.

Here’s the Perl script:

And here’s the cygrunsrv command line I used to install the Windows service:

From there, it should just be a matter of issuing ‘sc start ‘, and you should be good to go — remember that, by default, cygrunsrv services log to /var/log/ .log, so if anything misbehaves, that’s the first place to look for a reason why.

One thing to keep in mind is that, when you run the VM this way, it will run under the built-in SYSTEM account, rather than your own. This being the case, you won’t be able to administer the VM via the VirtualBox console while it’s running as a service; it will appear to be in the «Powered off» state, and you won’t be able to get to its settings. (Trying to power on the VM while it’s running as a service is not recommended — I don’t know what will happen, but at best it’ll be a no-op, and at worst it’ll hose your VM.) If you need to change the VM’s settings or access the console, stop the service first (and wait for VBoxHeadless.exe to exit), and then configure it/power it up in the VirtualBox console as you normally would.

You could probably solve this problem by installing a second interactive service to run the VirtualBox console; since that would run the console under the SYSTEM account as well, it’d most likely be able to see and manage the running VM. I haven’t had a need to do that myself, so I’m not sure it would work, but I don’t see a reason why it wouldn’t. (If you try it, I’d appreciate a comment to this answer, letting me know how it worked out for you. Thanks!)

Оцените статью