Ticket #3549 (closed enhancement: fixed)

Opened 13 years ago

Last modified 10 years ago

VBoxHeadless is not headless on Windows => Fixed in SVN

Reported by: rasker Owned by:
Component: other Version: VirtualBox 2.1.4
Keywords: vboxheadless service Cc:
Guest type: Linux Host type: other



I have been trying to run vboxheadless as a windows service (see I have got it working alright but it does not run truely headless as it needs a console for stdout. Starting virtualbox without the ability to open a console (disabling 'allow service to interact with the desktop') makes it error out with a large (possibly meaningless) minus number.

I'm not sure exactly how it works but I read that on windows createprocess() can redirect it's stdout and stderr to files. For example

Another option to give flexible log output might be to use logger.dll which can be found here -> logger.dll can log to a file, the event log or to stdout/stderr. It seems to also have a linux version but i'm not sure if this helps.

Is it possible to add an option to redirect the stdout/stderr to a file or the event log?

Change History

comment:1 Changed 13 years ago by frank

Open a headless session with VBoxManage startvm VM_NAME -type vrdp.

comment:2 Changed 13 years ago by rasker

The problem with doing it that way is that vboxheadless is spawned by the vboxsvc process (as in is a child of vboxsvc). Both these processes are detached from the service wrapper (running under a svchost process I guess as a COM server) that started them so the service fails to start (not really, as vboxheadless is running, but windows service manager thinks it has failed).

In addition, even starting it using vboxmanage opens a console window as the machine sends some data to stdout (copyright notice and port number). It would be great if vboxheadless was able to be started either without it sending anything to stdout or being able to redirect stdout to a file or nul.

comment:3 Changed 13 years ago by rasker

Sorry, the vboxsvc and vboxheadless processes run under a svchost process. The service wrapper and vboxmanage run as child processes of services.exe.

comment:4 Changed 13 years ago by rasker

Just to clarify the original request. It is not the output of the virtual machine at question here. It is the output of the vboxheadless executable itself that is the problem.


comment:5 Changed 12 years ago by jessicah

I agree. I don't use vbox as a service; just start it up in headless mode when I want the VM running.

Is it possible you could add an option to fork the VM? Say you still print the copyright and port number (if VRDP is enabled; I personally don't use) to stdout as you currently do, then the parent process returns to the console?

Like vboxheadless --startvm "My VM" --vrdp off --fork. It's silly to have to invent VBScripts to do this =/

comment:6 Changed 11 years ago by rossmeissl

This is a hack, but you can use TrayIt to put the console window in the tray.

comment:7 Changed 11 years ago by justinjhayes

I'm also wondering if anyone has looked at addressing this recently? I'm using Virtual Box 3.2.8 and the same issue still occurs. I've tried running it inside GNU Screen under Cygwin, but I'm having trouble getting that to work too.

Any ideas?

comment:8 Changed 11 years ago by timob

I've found a workaround that seems to work. Use the "at" command to schedule a task. So for me this was:

c:> at 19:59 "c:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe" -s mars

It does not show up in GUI as running, but "vboxmanage list vms", lists the vm running.

comment:9 in reply to: ↑ description Changed 11 years ago by KB

Another workaround, paste in vbs file:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe"" --
  startvm Xubuntu64 --vrdp=off", 0

Note the delicious use of doublequotes...

comment:10 Changed 11 years ago by trakos

Easy workaround: just change the subsystem byte to 0002, it won't output anything then, but it also won't open cmd.

You can use PE header patcher ( - copy VBoxHeadless.exe to VBoxReallyheadless.exe, open it with PE header patcher, change the subsystem from windows console to windows GUI and click 'save'. Then use the VBoxReallyheadless.exe instead of VBoxHeadless.exe.

You will have to use the original version of file to see the output again.

PS: Personally, I did it the hard way, without PE header patcher - just using hex editing (change the 324th - i.e. 144 in hex - byte from 0003 to 0002) ;)

comment:11 Changed 10 years ago by romw

I work on the BOINC project ( and we have begun work on integrating VirtualBox into the BOINC Desktop Grid Environment. We ran into this issue with multiple command line applications on Windows. Basically most applications are command line applications are compiled to be a part of the console subsystem on Windows, which automatically launches a conhost.exe process to display a console window regardless if you use it or not.

To work around this issue you just need to tell the linker that you are linking a windows application which uses the windows subsystem instead of the console subsystem.

I'm not quite familiar with the Vbox build system but adding the following flags to g++ during the link operation should do what 'Trakos' suggested with the hex editor modification.

vboxheadless_LDFLAGS +=-Wl,--subsystem,windows -mwindows 
vboxheadless_LDFLAGS +=-Wl,--subsystem,windows -mwindows 

Now depending on your build environment you may need to add an additional function called WinMain(), if you do need to specify WinMain() here is some quick and dirty code you can use to redirect to main(). Just add it after the main() function definition.


// take a string containing some space separated words.
// return an array of pointers to the null-terminated words.
// Modifies the string arg.
// Returns argc

#define NOT_IN_TOKEN                0
#define IN_UNQUOTED_TOKEN           3

int parse_command_line(char* p, char** argv) {
    int state = NOT_IN_TOKEN;
    int argc=0;

    while (*p) {
        switch(state) {
        case NOT_IN_TOKEN:
            if (isspace(*p)) {
            } else if (*p == '\'') {
                argv[argc++] = p;
                state = IN_SINGLE_QUOTED_TOKEN;
            } else if (*p == '\"') {
                argv[argc++] = p;
                state = IN_DOUBLE_QUOTED_TOKEN;
            } else {
                argv[argc++] = p;
                state = IN_UNQUOTED_TOKEN;
            if (*p == '\'') {
                *p = 0;
                state = NOT_IN_TOKEN;
            if (*p == '\"') {
                *p = 0;
                state = NOT_IN_TOKEN;
        case IN_UNQUOTED_TOKEN:
            if (isspace(*p)) {
                *p = 0;
                state = NOT_IN_TOKEN;
    argv[argc] = 0;
    return argc;

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
    LPSTR command_line;
    char* argv[100];
    int argc;

    command_line = GetCommandLine();
    argc = parse_command_line(command_line, argv);
    return main(argc, argv);

comment:12 Changed 10 years ago by frank

  • Status changed from new to closed
  • Resolution set to duplicate
  • Summary changed from vboxheadless is not headless on windows to VBoxHeadless is not headless on Windows => Fixed in SVN

romw, thanks for the suggestion but actually your solution is not what we want to implement. The VBoxHeadless application should actually DO write to the current console if started from cmd.exe but should not open a separate window if started from VBoxSVC. The (hopefully) correct solution is implemented in r38618.

This fix will be included in the next maintenance release.

comment:13 Changed 10 years ago by frank

  • Status changed from closed to reopened
  • Resolution duplicate deleted

Grr, closed by accident...

comment:14 Changed 10 years ago by frank

You can download a test build from  here.

comment:15 Changed 10 years ago by romw

That worked. vboxheadless.exe no longer opens a console window when launched from vboxsvc.exe.

comment:16 Changed 10 years ago by frank

  • Status changed from reopened to closed
  • Resolution set to fixed

VBox 4.1.4 contains the fix.

Note: See TracTickets for help on using tickets.
ContactPrivacy policyTerms of Use