Hi Brad.

I have used the Windows Service project template in Visual Studio and made
my own service for starting/stopping and suspending VirtualBox. I use
VirtualBox to run a minimalistic Linux system on windows servers so I have
a nice server environment on windows hosts.

/ Jakob Simon-Gaarde

Notes:
I found that I needed to set some environment variables before the service
could spawn the guest system.
Here is my OnStart-method of the service which starts the virtual machine
capa-server:

  void OnStart(String* args[]) {

    // Parameters
    char *spawn_args[10];
    spawn_args[0] = new char[strlen(m_capa_path) + 1 +
strlen("VBoxHeadless.exe")+1];
    sprintf(spawn_args[0], "%s\\%s", m_capa_path, "VBoxHeadless.exe");

    spawn_args[1] = new char[strlen("-startvm")+1];
    strcpy(spawn_args[1], "-startvm");

    spawn_args[2] = new char[strlen("capa-server")+1];
    strcpy(spawn_args[2], "capa-server");

    spawn_args[3] = NULL;

    // Environment
    char *spawn_env[10];

    spawn_env[0] = new char[strlen("VBOX_USER_HOME=") + strlen(m_data_path)
+ 1];
    sprintf(spawn_env[0], "%s%s", "VBOX_USER_HOME=", m_data_path);

    spawn_env[1] = new char[strlen("SystemRoot=C:\\WINDOWS") + 1];
    strcpy(spawn_env[0], "SystemRoot=C:\\WINDOWS");
           spawn_env[2] = NULL;

    // Spawn the virtual machine
    _spawnve(_P_NOWAIT,spawn_args[0],spawn_args,spawn_env);

    delete [] spawn_args[0];
    delete [] spawn_args[1];
    delete [] spawn_args[2];
    delete [] spawn_env[0];
    delete [] spawn_env[1];

    m_status = VM_RUNNING;
  }



On Tue, 20 Jan 2009 14:15:36 -0500, "Oster, Bradley C CTR SAF/FMP (AFFSO)"
<[email protected]> wrote:
> I keep thinking that is the issue but I can't seem to get around it. I
have
> it logging on as me (I think...) and I have admin rights. I also
installed
> VirtualBox from my account and so the info is under me in the Documents
> and Settings. 
> 
> I must not be doing it right because I can run a batch file (as well as
> using the command line) to start up VirtualBox just fine but I have not
> been able to get a service to do that simple task yet.
> 
> Brad
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Kevin Gagel
> Sent: Tuesday, January 20, 2009 2:06 PM
> To: VirtualBox end user list
> Subject: Re: [vbox-users] Run VirtualBox as a service in Windows
> 
> What permissions does it have? Are you running it with admin privileges?
> That error looks like one I've seen before which usually indicated some
> kind of security issue because it could not access an object.
> 
> Kevin W. Gagel
> Network Administrator
> Local 5448
> My blog:
> http://mail.cnc.bc.ca/blogs/gagel
> My shared files:
> http://mail.cnc.bc.ca/users/gagel
> 
> 
> --- Original message ---
> Subject: Re: [vbox-users] Run VirtualBox as a service in Windows
> From: "Oster, Bradley C CTR SAF/FMP (AFFSO)" <[email protected]>
> To: VirtualBox end user list <[email protected]>
> Date: 20/01/2009 11:03 AM
> 
> Thank you! I have tried this and I get the same result that I have had 
> using other options... the service starts and tries to run the 
> VBoxHeadless.exe with all the proper parameters. Watching the 
> TaskManager, I see the headless program start and then stop almost 
> immediately. Upon checking the log for the service, it says that 
> VBoxHeadless stopped with an exit code of -2147024809. I have looked 
> this up and cannot find any useful information. 
> 
> Brad 
> 
> -----Original Message--

_______________________________________________
vbox-users mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-users

Reply via email to