How to run a headless VM with VBoxManager as a windows service

7

1

Objective

I want to run this command VBoxManage startvm MyVM --type headless at the boot system just like a service (postgres, apache) does.

What i've tried

1. I've tried to create a service using sc command

I've found over the internet that could be the solution so i tried all this versions:

  • sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage.exe startvm MyVM --type headless"

  • sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage startvm MyVM --type headless"

No success, so i tried to suppress the verbose output of the command

  • sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage.exe startvm MyVM --type headless > NUL"

  • sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage startvm MyVM --type headless"

Still no results. All this version returned me a 1053 error. So the last call was to add the Virtualbox command to the Path


  • sc create "vboxMyVMService" binPath= "VBoxManage.exe startvm MyVM --type headless"

  • sc create "vboxMyVMService" binPath= "VBoxManage startvm MyVM --type headless"

suppressing output

  • sc create "vboxMyVMService" binPath= "VBoxManage.exe startvm MyVM --type headless > NUL"

  • sc create "vboxMyVMService" binPath= "VBoxManage startvm MyVM --type headless > NUL"

No positive result always 1053 error.

2. Assign Computer Startup Scripts

I followed this tutorial with my last hope, but no success.

What left

I'm thinking about to download the Visual Studio and try something related to create a service project.


So guys, where is my mistake? Is there hope to me?


FAQs

  1. Can you switch you OS to linux?

    • No. It's out of question.
  2. Why you need this VM to startup at with the system?

    • Unfortunately this windows 7 host is a small server for the application running over the VM. The machine it's not mine and it's the only option they gave to me to make the deploy.
  3. Why you are not making the deploy of the application inside the windows host?

    • I'm not running PHP, or any .NET stuff, so no.

vyscond

Posted 2015-06-02T22:52:18.150

Reputation: 71

Rather simpler. Have you tried using Task Scheduler with an "On Startup" trigger? Though you might actually need something more like "At log on" depending on whether you need to give time for other services to start which I suspect you do. – Julian Knight – 2015-06-02T23:04:41.993

what about sticking the vbox X --type headless command in a batch script that you stick in the Startup folder, or in the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run .. does it have to be a service? Just curious if you need the netstart functionality over just starting the VM in headless mode at startup? – txtechhelp – 2015-06-02T23:41:28.787

@JulianKnight i need the vm running without the need to login on a specific account :( But i will check the Scheduler see if can be a plan B – vyscond – 2015-06-03T00:29:57.123

@txtechhelp didn't find anything about this folder, i will try it in a minute too. – vyscond – 2015-06-03T00:30:33.473

Trying using srvany as the service executable and use that to launch your VBoxManage command. Seems like the task scheduler idea on startup would also work. – ssnobody – 2015-06-03T00:45:31.463

@ssnobody can you provide the steps to use srvany? – vyscond – 2015-06-03T00:49:19.777

https://support.microsoft.com/en-us/kb/137890 – ssnobody – 2015-06-03T00:49:37.383

@JulianKnight @ssnobody i've tried the task scheduler but i got this message The operation being requested was not performed because the user has not logged on to the network.The specified service does not exist(0x800704DD) it's seems that i need now to force a login before starting the .bat file, right? – vyscond – 2015-06-03T00:50:41.913

What does the batch file look like? Which service is it trying to start and failing? I don't believe you need to log on before running the VBoxManage command. Over at http://www.wolfsoftwaresystems.com/code/server-stuff/the-operation-being-requested-was-not-performed-because-the-user-has-not-logged-on-to-the-network-the-specified-service-does-not-exists-0x800704dd/ it says you must check the radio button highlighted “Run whether user is logged on or not”. once this is checked you will be prompted for the password you are trying to execute the task as.

– ssnobody – 2015-06-03T00:53:13.863

@ssnobody the batch file looks like this now "C:\Progman Files\Oracle\VirtualBox\VBoxManage.exe" startvm MyVM --type headless. I checked the box about “Run whether user is logged on or not” after the reboot the scheduler show 0x0 as response, but the VM still not being called up.

I also tried the srvany.exe which the service created runs without the error code 1053 but the VM show up as aborted. – vyscond – 2015-06-03T01:08:46.700

If it shows up as aborted look for and post the vbox log. Also, I wouldn't try both the startup script and the service at the same time, I don't know how virtualbox will respond to multiple things trying to start the same virtual machine. – ssnobody – 2015-06-03T01:12:15.587

@ssnobody i tried this tutorial which is almost the same thing i did but using VBoxHeadless command. So in my machine i had two scheduled task the 1) run the .bat as described on the question and the 2) is the running directly the VBoxHeadless. All this failures seems to lead about the order of windows to execute the base drivers/services that we need to run a vbox VM, but if is it so i'm out of my league again.

– vyscond – 2015-06-03T11:59:06.877

batch files won't run under srvany. Set srvany to trigger the actual VB manage command you want. Then, set the service to depend on the virtualbox services so it won't start the srvany service until after the virtualbox services. https://support.microsoft.com/en-us/kb/193888

– ssnobody – 2015-06-04T21:53:09.467

@ssnobody i tried using the VBoxManager and VBoxHeadless directly but no success :/ so i find this tool VBoxVmService which did what i wanted without much pain.

– vyscond – 2015-06-07T13:32:34.923

Looks good. Probably worth posting as an answer... – ssnobody – 2015-06-07T23:18:53.740

@ssnobody well did you tested the srvany on your machine? Because i don't wanna make people believe that is not a real way achieve. If can teste it and say it worked (at least for you) it worth post as a answer, and just append the VBoxVmService as a second option. – vyscond – 2015-06-08T13:00:19.903

I didn't try it on my machine but have used srvany for controlling many binaries without issue and the post over at https://forums.virtualbox.org/viewtopic.php?f=2&t=15164 certainly suggests it's a workable solution. I would recommend you post your solution as the answer you used (since it's the only one you know for sure does work for you). Those interested in the details of the srvany can always direct themselves to the comments or someone who can actually try it can post it a separate answer.

– ssnobody – 2015-06-09T21:33:10.280

Answers

9

I run with NSSM.

Create a NSSM service in prompt like:

  1. nssm/win64/nssm.exe install vbox

  2. Select exec VBoxHeadless.exe like image:

    NSSM install service

  3. Use your Windows Account in Logon (this is very important)

  4. Install service

Works for me.

Renato Barros

Posted 2015-06-02T22:52:18.150

Reputation: 91

Great program. I used "startvm WindowsXP --type headless" as my arguments. Works great – Peter Berbec – 2018-02-14T08:59:00.650

When stopping such service, it always does hard shutdown of VM? I do not see mechanism to NSSM wait till machine shutdown correctly. – user2956477 – 2019-07-23T18:00:19.013

4

I wasn't able to find a mechanism to start a VM as service with VBoxManager command without anybody required to login first.

I enabled my Ubuntu Server VM to run as service using the VBoxVmService tool. http://vboxvmservice.sourceforge.net/

Brief Description: VBoxVmService is a Windows application that allows you to run Oracle's VirtualBox VMs from within a native Windows service entity.

The main reason i required this is, to start the VM without anybody required to login. Mine being a developer workstation, it get's restarted for updates, and i sometimes forget to start the VM until someone pokes me.

Here's how it works:

  • Ensure the required VM starts and works fine without errors. Else will be tough to debug digging through the logs.
  • Upon installation VMBoxService set's it's executable as a windows service
  • Edit it's configuration INI file (Refer here for full documented sample)
  • Reboot the machine or just start the VMBoxService's installed windows service
  • Following is a sample INI

    [Settings]
    VBOX_USER_HOME=C:\Users\YOUR_NAME_HERE\.VirtualBox
    PauseShutdown=8000
    [Vm0]
    VmName=ubuntu-server                                              
    ShutdownMethod=savestate                                    
    AutoStart=yes
    

Prasanna Kumar Ranjan

Posted 2015-06-02T22:52:18.150

Reputation: 41

Might be worth improving your answer. Good software recommendations answers are 'how' not 'what'. Maybe edit your answer to talk about how you would use this software to start your vm as a service and what's the advantages of this. – Journeyman Geek – 2016-06-15T23:36:29.923