Index: trunk/src/VBox/Frontends/VBoxHeadless/Makefile.kmk
===================================================================
--- trunk/src/VBox/Frontends/VBoxHeadless/Makefile.kmk	(revision 37473)
+++ trunk/src/VBox/Frontends/VBoxHeadless/Makefile.kmk	(revision 38607)
@@ -30,6 +30,13 @@
  PROGRAMS += VBoxHeadlessHardened
  DLLS += VBoxHeadless
+ VBOX_WITH_HEADLESS_DLL = 1
 else
- PROGRAMS += VBoxHeadless
+ if "$(KBUILD_TARGET)" == "win"
+  PROGRAMS += VBoxHeadlessW VBoxHeadlessC
+  DLLS += VBoxHeadless
+  VBOX_WITH_HEADLESS_DLL = 1
+ else
+  PROGRAMS += VBoxHeadless
+ endif
 endif
 
@@ -42,9 +49,24 @@
 VBoxHeadlessHardened_NAME = VBoxHeadless
 
+#
+# Console subsystem VBoxHeadless.
+#
+VBoxHeadlessC_TEMPLATE = VBOXMAINCLIENTEXE
+VBoxHeadlessC_SOURCES = VBoxHeadless-win.cpp
+VBoxHeadlessC_NAME = VBoxHeadless
+VBoxHeadlessC_LDFLAGS.win = /SUBSYSTEM:console
+VBoxHeadlessC_LIBS += $(PATH_STAGE_LIB)/VBoxHeadless$(VBOX_SUFF_LIB)
+
+#
+# Windows subsystem VBoxHeadless.
+#
+VBoxHeadlessW_EXTENDS = VBoxHeadlessC
+VBoxHeadlessW_NAME = VBoxHeadlessW
+VBoxHeadlessW_LDFLAGS.win = /SUBSYSTEM:windows
 
 #
 # VBoxHeadless
 #
-VBoxHeadless_TEMPLATE  := $(if $(VBOX_WITH_HARDENING),VBOXMAINCLIENTDLL,VBOXMAINCLIENTEXE)
+VBoxHeadless_TEMPLATE  := $(if $(VBOX_WITH_HEADLESS_DLL),VBOXMAINCLIENTDLL,VBOXMAINCLIENTEXE)
 VBoxHeadless_DEFS       = VBOX_FFMPEG
 VBoxHeadless_SOURCES    = VBoxHeadless.cpp
Index: trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless-win.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless-win.cpp	(revision 38607)
+++ trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless-win.cpp	(revision 38607)
@@ -0,0 +1,122 @@
+/* $Id$ */
+/** @file
+ * VBoxHeadless-win - The VirtualBox Headless frontend for running VMs on servers.
+ *                    windows exe stub.
+ */
+
+/*
+ * Copyright (C) 2011 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+#include <iprt/cdefs.h>
+
+#include <windows.h>
+#include <tchar.h>
+
+extern "C" DECLIMPORT(int) ExecTrustedMain(int argc, char **argv, char **envp);
+
+int main(int argc, char **argv, char **envp)
+{
+    return ExecTrustedMain(argc, argv, envp);
+}
+
+static LRESULT CALLBACK WindowProc(HWND hwnd,
+    UINT uMsg,
+    WPARAM wParam,
+    LPARAM lParam
+)
+{
+    if(uMsg == WM_DESTROY)
+    {
+        PostQuitMessage(0);
+        return 0;
+    }
+    return DefWindowProc (hwnd, uMsg, wParam, lParam);
+}
+
+static LPCTSTR g_WndClassName = _T("VBoxNetDHCPClass");
+
+static DWORD WINAPI MsgThreadProc(__in  LPVOID lpParameter)
+{
+     HWND                 hwnd = 0;
+     HINSTANCE hInstance = (HINSTANCE)GetModuleHandle (NULL);
+     bool bExit = false;
+
+     /* Register the Window Class. */
+     WNDCLASS wc;
+     wc.style         = 0;
+     wc.lpfnWndProc   = WindowProc;
+     wc.cbClsExtra    = 0;
+     wc.cbWndExtra    = sizeof(void *);
+     wc.hInstance     = hInstance;
+     wc.hIcon         = NULL;
+     wc.hCursor       = NULL;
+     wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
+     wc.lpszMenuName  = NULL;
+     wc.lpszClassName = g_WndClassName;
+
+     ATOM atomWindowClass = RegisterClass(&wc);
+
+     if (atomWindowClass != 0)
+     {
+         /* Create the window. */
+         hwnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
+                 g_WndClassName, g_WndClassName,
+                                                   WS_POPUPWINDOW,
+                                                  -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
+
+         if (hwnd)
+         {
+             SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0,
+                          SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
+
+             MSG msg;
+             while (GetMessage(&msg, NULL, 0, 0))
+             {
+                 TranslateMessage(&msg);
+                 DispatchMessage(&msg);
+             }
+
+             DestroyWindow (hwnd);
+
+             bExit = true;
+         }
+
+         UnregisterClass (g_WndClassName, hInstance);
+     }
+
+     if(bExit)
+     {
+         /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */
+         exit(0);
+     }
+
+     return 0;
+}
+
+/** (We don't want a console usually.) */
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+    NOREF(hInstance); NOREF(hPrevInstance); NOREF(lpCmdLine); NOREF(nCmdShow);
+
+    HANDLE hThread = CreateThread(
+      NULL, /*__in_opt   LPSECURITY_ATTRIBUTES lpThreadAttributes, */
+      0, /*__in       SIZE_T dwStackSize, */
+      MsgThreadProc, /*__in       LPTHREAD_START_ROUTINE lpStartAddress,*/
+      NULL, /*__in_opt   LPVOID lpParameter,*/
+      0, /*__in       DWORD dwCreationFlags,*/
+      NULL /*__out_opt  LPDWORD lpThreadId*/
+    );
+
+    if(hThread != NULL)
+        CloseHandle(hThread);
+
+    return main(__argc, __argv, environ);
+}
Index: trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 37473)
+++ trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 38607)
@@ -1346,4 +1346,30 @@
 
 #ifndef VBOX_WITH_HARDENING
+/*
+ * Used by windows exe stub code
+ */
+extern "C" DECLEXPORT(int) ExecTrustedMain(int argc, char **argv, char **envp)
+{
+    // initialize VBox Runtime
+    int rc = RTR3InitAndSUPLib();
+    if (RT_FAILURE(rc))
+    {
+        RTPrintf("VBoxHeadless: Runtime Error:\n"
+                 " %Rrc -- %Rrf\n", rc, rc);
+        switch (rc)
+        {
+            case VERR_VM_DRIVER_NOT_INSTALLED:
+                RTPrintf("Cannot access the kernel driver. Make sure the kernel module has been \n"
+                        "loaded successfully. Aborting ...\n");
+                break;
+            default:
+                break;
+        }
+        return 1;
+    }
+
+    return TrustedMain(argc, argv, envp);
+}
+
 /**
  * Main entry point.
@@ -1351,23 +1377,5 @@
 int main(int argc, char **argv, char **envp)
 {
-    // initialize VBox Runtime
-    int rc = RTR3InitAndSUPLib();
-    if (RT_FAILURE(rc))
-    {
-        RTPrintf("VBoxHeadless: Runtime Error:\n"
-                 " %Rrc -- %Rrf\n", rc, rc);
-        switch (rc)
-        {
-            case VERR_VM_DRIVER_NOT_INSTALLED:
-                RTPrintf("Cannot access the kernel driver. Make sure the kernel module has been \n"
-                        "loaded successfully. Aborting ...\n");
-                break;
-            default:
-                break;
-        }
-        return 1;
-    }
-
-    return TrustedMain(argc, argv, envp);
+    return ExecTrustedMain(argc, argv, envp);
 }
 #endif /* !VBOX_WITH_HARDENING */
