5

I'm trying to run VirtualBox VM's in the background from a service. I'm having trouble starting a process the way I desire. I'd like to start the virtualbox guest in headless mode as a separate process and show nothing as far as GUI.

Here's what I've tried:

From command line:

start vboxheadless -s "Ubuntu Server"

In C#:

        ProcessStartInfo info = new ProcessStartInfo
        {
            UseShellExecute = false,
            RedirectStandardOutput = true,
            ErrorDialog = false,
            WindowStyle = ProcessWindowStyle.Hidden,
            CreateNoWindow = true,
            FileName = "C:/program files/sun/virtualbox/vboxheadless",
            Arguments = "-s \"Ubuntu Server\""
        };

        Process p = new Process();
        p.StartInfo = info;
        p.Start();

        String output = p.StandardOutput.ReadToEnd(); //BLOCKS! (output stream isnt closed)

I want to be able to get the output to know if starting the server was a success. However, it seems as though the window that's spawned never closes its output stream.

It's also worth mentioning that I've tried using vboxmanage startvm "Ubuntu Server" --type=vrdp. I can determine whether the server started properly using this. But it shows a new command prompt window for the newly started VirtualBox guest.

2 Answers 2

6

Just in case somebody faces the thing again here is what I do for this...

start-process "vboxheadless" "-s ubuntu" -WindowStyle Hidden

either put it in a powershell script or type in a powershell console window. You may create a shortcut or an alias etc.

1
  • works well even in Windows 10, tho in my case I needed to specify the full path to vboxheadless. You can save it as a one-liner .ps1 file in %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup and then it will run headless at start up.
    – gogoud
    Jan 20, 2016 at 10:46
0

I've recently managed to do it here. The solution is not very good: I don't like Windows development.. but it works, what else can you desire? :))

You must log in to answer this question.