HOWTO - virtualbox as a service on Windows (srvstart.exe)
-
- Posts: 5
- Joined: 4. May 2009, 17:33
- Primary OS: MS Windows XP
- VBox Version: PUEL
- Guest OSses: Windows Server, Linux (gentoo)
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Remote Desktop made the trick, with vnc i was able to get the cmd window shown. It was easy to find out i had to move my VirtualBox.xml file to "Default User" instead of "LocalService" folder, because virtualbox was searching in the previous folder (don' know why).
Im so glad it works.
Kind regards
Chaos
Im so glad it works.
Kind regards
Chaos
Please write about differences to vboxvmservice
Hi, thanks for you efforts - it is very nice to see people do thigs that software engeneers should have done already.
One question: ould you please explain the differences between your solution and vboxvmservice - why is it better to do it "your" way than with vboxvmservice?
I am investiganting which options I have to start vm as a service - because virtualbox does not bring this option I now have to go through at least three options, that eats a lot of time.
To sun team: yes, of course, it should be on top of your todo list to implement a run-vbox-as-a-servcie option.
Thanhks!
One question: ould you please explain the differences between your solution and vboxvmservice - why is it better to do it "your" way than with vboxvmservice?
I am investiganting which options I have to start vm as a service - because virtualbox does not bring this option I now have to go through at least three options, that eats a lot of time.
To sun team: yes, of course, it should be on top of your todo list to implement a run-vbox-as-a-servcie option.
Thanhks!
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
There isn't a huge difference between the two approaches as interacting with a service is pretty locked down but they end in the same result. The vboxvmservice is slightly more complicated and uses more modern tools. srvstart is an old tool not updated recently but adequately gets the job done (with some fiddling of configs). I've been in contact with the author and he says he doesn't have time to continue development but he might be able to convince his son to have a go
I investigated modernising srvstart and it looks like .net framework version 2 and above has much of what is needed to make a better version, and can even be done in visual basic. The design I came up with would go something like this:
1) A service process to handle *timely* communication with the service manager.
2) A configuration parsing part, either registry based as in srvstart or xml/ini based configurations with basically the same options as in srvstart. It could perhaps be improved to run multiple commands for each service management option (start/stop etc) so that you can for example do cleanups or send emails to say <blah blah broke on some date> and be able to cope with spaces in arguments in a better way.
3) A threaded command launcher. It would have to be threaded so as not to hold up responses to the service manager (see 1). The service manager (very generally) determines whether a service is working or not by time a response takes to be received from the service. The service must send the 'i'm still starting' and the 'i'm still stopping' responses as virtualbox startups can take a while.
Additionally there are 127 generic commands that can be sent to the service from the service manager. These can be used to provide more granular control of the service.
The application can be made to be run once for each process that needs to be managed (each virtualbox instance) or a single instance can manage multiple instance of virtualbox or for more flexibility both. A single service instance for multiple virtualbox instances would probably require a custom gui to interact with the service (service start/stop would start or stop *all* managed processes in this scenario). If the 127 generic commands is too limiting then some kind of remoting interface would probably work which would also enable controlling the service from other machines.
And that's as far as I got I was amazed (still am!) to find that this could all be done in visual basic + .netv2. Much of what is needed can be found in the code examples at www.codeproject.com.
R
I investigated modernising srvstart and it looks like .net framework version 2 and above has much of what is needed to make a better version, and can even be done in visual basic. The design I came up with would go something like this:
1) A service process to handle *timely* communication with the service manager.
2) A configuration parsing part, either registry based as in srvstart or xml/ini based configurations with basically the same options as in srvstart. It could perhaps be improved to run multiple commands for each service management option (start/stop etc) so that you can for example do cleanups or send emails to say <blah blah broke on some date> and be able to cope with spaces in arguments in a better way.
3) A threaded command launcher. It would have to be threaded so as not to hold up responses to the service manager (see 1). The service manager (very generally) determines whether a service is working or not by time a response takes to be received from the service. The service must send the 'i'm still starting' and the 'i'm still stopping' responses as virtualbox startups can take a while.
Additionally there are 127 generic commands that can be sent to the service from the service manager. These can be used to provide more granular control of the service.
The application can be made to be run once for each process that needs to be managed (each virtualbox instance) or a single instance can manage multiple instance of virtualbox or for more flexibility both. A single service instance for multiple virtualbox instances would probably require a custom gui to interact with the service (service start/stop would start or stop *all* managed processes in this scenario). If the 127 generic commands is too limiting then some kind of remoting interface would probably work which would also enable controlling the service from other machines.
And that's as far as I got I was amazed (still am!) to find that this could all be done in visual basic + .netv2. Much of what is needed can be found in the code examples at www.codeproject.com.
R
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
hi, thanks for the quick answer. I did not exactly understand why are you using srvsrart.exe, if vboxvmservice does exist?
Another question: does "your" solution work with Vista and Windows 7?
Thanks again!
Another question: does "your" solution work with Vista and Windows 7?
Thanks again!
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
vboxvmservice has more dependencies and is slightly harder to get installed (heh, well that's debatable). Actually I started down this road because the vboxvmservice documentation didn't explain all the nitty gritty details of why it was needed so I started experimenting with what most people would go for in the first instance, srvany from microsoft. that led to various place and then to here. I just posted my findings (see my sig) so that people didn't have to do my experiments again (or they could as I had posted the steps). It's *not* offerred as a better alternative to vboxvmservice, just as another way of doing the same thing.
It's down to the individual to have a look at the available documentation and choose what best fits thier situation. Try them both and let me know what you find.
R
It's down to the individual to have a look at the available documentation and choose what best fits thier situation. Try them both and let me know what you find.
R
-
- Posts: 1
- Joined: 7. Aug 2009, 05:07
- Primary OS: MS Windows XP
- VBox Version: OSE other
- Guest OSses: Ubuntu
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
someone made a step by step tutorial to run virtualbox as service on windows on http://thelivedevil.com
he use srvstart method with some modifications. i tried it myself (on XP) and it's working. perhaps this can help
he use srvstart method with some modifications. i tried it myself (on XP) and it's working. perhaps this can help
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Thanks. Both blog articles are based on this howto so it is a great report from the trenches.
Direct links to the articles:
http://thelivedevil.com/virtualbox/how- ... n-windows/
http://thelivedevil.com/virtualbox/how- ... taneously/
R
Direct links to the articles:
http://thelivedevil.com/virtualbox/how- ... n-windows/
http://thelivedevil.com/virtualbox/how- ... taneously/
R
-
- Posts: 1
- Joined: 10. Aug 2009, 16:56
- Primary OS: MS Windows 2008
- VBox Version: OSE other
- Guest OSses: sbs 2008
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Hello,
I'm new on this forum.
I've find your solution and i've test it on my XP. All is OK.
Now, I want to do the same thing in my sbs 2008 server and i can't set env=USERPROFIL as LocalService because there is no LocalService folder in Users.
Someone has this install done in a sbs 2008 or Vista ? If yes, how are you configure the .ini ?
Thanks for your help.
Ericzen
I'm new on this forum.
I've find your solution and i've test it on my XP. All is OK.
Now, I want to do the same thing in my sbs 2008 server and i can't set env=USERPROFIL as LocalService because there is no LocalService folder in Users.
Someone has this install done in a sbs 2008 or Vista ? If yes, how are you configure the .ini ?
Thanks for your help.
Ericzen
-
- Posts: 95
- Joined: 18. Feb 2008, 11:51
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: WinXP/Debian/OSX
- Location: Germany
- Contact:
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
now that's quite a nice way of looking at it... If I would still be maintaining vboxvmservice, I think I would have rewritten it from scratch in the meantime... so my "official" comment on the complexity-level of vboxvmservice would rather be:rasker wrote:vboxvmservice has more dependencies and is slightly harder to get installed ...
mattz wrote: its' codebase is a complicated mess and the install procedure can easily outwit even a sophisticated windows admin.
Good thing that people don't give up on the issue though. It is good to see that VBoxVmService is still community supported and yet new people try new and alternative ways to get the job done!
best, -- mattz
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Hi Matz,
Right, each has pros and cons and that was what I was trying to demonstrate in the howtos's even though I did not cover vboxvmservice (there was quite enough info in the vbioxvmservice thread(s)). I wouldn't be so critical of vboxvmservice though. It does it's job quite well at the cost of some complexity particularly for users who are not so technical.
Did you see my earlier post regarding the skeletal design of an application that could resolve many of the issues and provide the needed functionality? It could be generalised to apply to more than vboxvmservice. I would be interested in collaborating with someone who has the visual basic or c# skills to implement something like this, although I don't think it would require any great effort to produce a working proof of concept. Unfortunately, when it come to writing code my brain experiences the 'round hole, square peg' issue and elicits guffaws from those who can actually code
R
Right, each has pros and cons and that was what I was trying to demonstrate in the howtos's even though I did not cover vboxvmservice (there was quite enough info in the vbioxvmservice thread(s)). I wouldn't be so critical of vboxvmservice though. It does it's job quite well at the cost of some complexity particularly for users who are not so technical.
Did you see my earlier post regarding the skeletal design of an application that could resolve many of the issues and provide the needed functionality? It could be generalised to apply to more than vboxvmservice. I would be interested in collaborating with someone who has the visual basic or c# skills to implement something like this, although I don't think it would require any great effort to produce a working proof of concept. Unfortunately, when it come to writing code my brain experiences the 'round hole, square peg' issue and elicits guffaws from those who can actually code
R
-
- Posts: 2
- Joined: 12. Aug 2009, 09:26
- Primary OS: MS Windows XP
- VBox Version: PUEL
- Guest OSses: Ubuntu
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
The method with srvstart works pretty well, however it does not stop the service at shutdown properly, such that it stops with poweroff.
What however works nicely is the "net stop <service>" command.
I used it in the general shutdown script of my computer and looks like it works (savestate returns).
----------------------------
Shutdown scripts can be accessed via gpedit.msc under computer configuration/windows settings/scripts.
I created a .bat file with a net stop command.
Furthermore is it possible to activate the output of that shutdown see script. gpedit.msc Administrative templates/system/scripts/
When you install the service with the windows service commander you can also modify the rights of common users (for example to start or stop the service) (security options)
------------------------------
Furthermore I intend to have a user that can use the VBoxmanage commands.
For that this user will have to have a console which runs under local service rights.
This can be done with the psexec tool from sysinternals (windows resource kit tools) with the -i -s options (but only from a shell with admin rights):
1. runas /user:<admin> cmd
2. psexec -i -s cmd (inside the new shell)
within this shell Virtualbox sees the machines running under localsystem.
--------------------------------
Interesting could be also a service that runs a shell and can be started and stopped only by the user that manages the Virtualbox machines.
Anyway all this is slightly dangerous because of the localsystem rights (which are practically admin rights)
But probably the service could be also run under the useracount or the localservice account
The problem is only that Virtualbox sees its running virtual machine
---------------------------------
For hiding the console window I used startx (which also allows you to set the priority better)
---------------------------------
I realised that even Virtualbox.exe can be run under localsystem and it sees the running virtual machine!
It does neither shutdown the VBoxheadless.exe when it is closed. Interesting...
best
Sönke Schmachtel
Copy of the reply under srvany.exe
What however works nicely is the "net stop <service>" command.
I used it in the general shutdown script of my computer and looks like it works (savestate returns).
----------------------------
Shutdown scripts can be accessed via gpedit.msc under computer configuration/windows settings/scripts.
I created a .bat file with a net stop command.
Furthermore is it possible to activate the output of that shutdown see script. gpedit.msc Administrative templates/system/scripts/
When you install the service with the windows service commander you can also modify the rights of common users (for example to start or stop the service) (security options)
------------------------------
Furthermore I intend to have a user that can use the VBoxmanage commands.
For that this user will have to have a console which runs under local service rights.
This can be done with the psexec tool from sysinternals (windows resource kit tools) with the -i -s options (but only from a shell with admin rights):
1. runas /user:<admin> cmd
2. psexec -i -s cmd (inside the new shell)
within this shell Virtualbox sees the machines running under localsystem.
--------------------------------
Interesting could be also a service that runs a shell and can be started and stopped only by the user that manages the Virtualbox machines.
Anyway all this is slightly dangerous because of the localsystem rights (which are practically admin rights)
But probably the service could be also run under the useracount or the localservice account
The problem is only that Virtualbox sees its running virtual machine
---------------------------------
For hiding the console window I used startx (which also allows you to set the priority better)
---------------------------------
I realised that even Virtualbox.exe can be run under localsystem and it sees the running virtual machine!
It does neither shutdown the VBoxheadless.exe when it is closed. Interesting...
best
Sönke Schmachtel
Copy of the reply under srvany.exe
-
- Posts: 1
- Joined: 23. Sep 2009, 20:18
- Primary OS: Ubuntu 8.04
- VBox Version: OSE self-compiled
- Guest OSses: Linux, XP, Win2K
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
About that large minus error number (like -2135228415): if "interact with desktop" is checked (or srvstart install_desktop was used) and you're still getting it, it can also be caused when we copy/link the VirtualBox.xml file into LocalService\.VirtualBox if there are relative path names inside the xml file.
This is especially true when we create the VM in the default location (%HOMEPATH%\.VirtualBox) instead of someplace like "%SystemDrive%\MyApp\.VirtualBox" and don't use a working directory in the service creation, because the default working directory and path to .VirtualBox are different between LocalService and whatever user we created the VM with.
If we are importing an appliance on a target machine, be aware also that VBox will by default put the imported disk image in %HOMEPATH% for the user executing the import command, ignoring the location on the orginating machine of the image exported, and ignoring the location on the originating machine of the appliance's exported, compressed vmdk image. In other words, doing an import that won't start VBox as a service from a master that will, then copying the VirtualBox.xml file(s) from the working installation to try to fix it, won't work.
To fix this in all cases, it is safe as of VirtualBox 3.0.6 to change all path names in all copies of VirtualBox.xml file (using NotePad, for instance) to absolute full paths, including the drive letter. Modifying that file improperly can wreck access to your VM's, all of them, so back it up first. The modification must be done with the VM's and the GUI off, of course. Get it working with the GUI before testing headless, then make absolutely sure the one in LocalService is identical to the one we are logged in as, then test it as a service.
Maybe the amazingly wonderful how-to should be updated?
About starup_dir: I've single-stepped the code in VS 2008 and found this information.
What will work is to srvstart install_desktop , then net start. Don't forget srvstart remove before the install .
This is especially true when we create the VM in the default location (%HOMEPATH%\.VirtualBox) instead of someplace like "%SystemDrive%\MyApp\.VirtualBox" and don't use a working directory in the service creation, because the default working directory and path to .VirtualBox are different between LocalService and whatever user we created the VM with.
If we are importing an appliance on a target machine, be aware also that VBox will by default put the imported disk image in %HOMEPATH% for the user executing the import command, ignoring the location on the orginating machine of the image exported, and ignoring the location on the originating machine of the appliance's exported, compressed vmdk image. In other words, doing an import that won't start VBox as a service from a master that will, then copying the VirtualBox.xml file(s) from the working installation to try to fix it, won't work.
To fix this in all cases, it is safe as of VirtualBox 3.0.6 to change all path names in all copies of VirtualBox.xml file (using NotePad, for instance) to absolute full paths, including the drive letter. Modifying that file improperly can wreck access to your VM's, all of them, so back it up first. The modification must be done with the VM's and the GUI off, of course. Get it working with the GUI before testing headless, then make absolutely sure the one in LocalService is identical to the one we are logged in as, then test it as a service.
Maybe the amazingly wonderful how-to should be updated?
About starup_dir: I've single-stepped the code in VS 2008 and found this information.
- The startup_dir value is used only with 'cmd' or 'any' in the srvstart command line.
- The startup_dir value must not have a drive letter in it (the _chdir() call does not work on my XP, at least).
- It must not have spaces in it. I think.
- It must exist (and be writable, I think).
What will work is to srvstart install_desktop , then net start. Don't forget srvstart remove before the install .
-
- Posts: 1
- Joined: 12. Oct 2009, 23:06
- Primary OS: MS Windows XP
- VBox Version: PUEL
- Guest OSses: Linux
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
I notice from earlier replies that some people have had trouble trying to get this to work on Vista, and nobody else seems to have posted an answer yet.
In fact this method does work on Vista, at least for me, but in step 2 the virtualbox.xml file needs to be copied to a different directory:
In fact this method does work on Vista, at least for me, but in step 2 the virtualbox.xml file needs to be copied to a different directory:
c:\Windows\System32\config\systemprofile\.VirtualBox\Otherwise the only problem was User Account Control getting in the way of installation (turn it off temporarily!)
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Thanks for posting this info!
-
- Posts: 1
- Joined: 15. Oct 2009, 13:25
- Primary OS: Ubuntu other
- VBox Version: OSE Debian
- Guest OSses: Windows
Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)
Hy there
I try it in a windows 2008 server but i'm stuck in the error: exception error 7...
I can run a console as service too, but never can't see it!
I run the service as local service and interact with desktop, and i'm in front of the server, but the console never show ups, however the service appear in task manager...
Anyone can help?
I try it in a windows 2008 server but i'm stuck in the error: exception error 7...
I can run a console as service too, but never can't see it!
I run the service as local service and interact with desktop, and i'm in front of the server, but the console never show ups, however the service appear in task manager...
Anyone can help?