Index: trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp	(revision 95099)
+++ trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp	(revision 95103)
@@ -83,4 +83,7 @@
 static com::Bstr g_bstrServiceName;
 
+/** Verbosity level. */
+unsigned             g_cVerbosity = 0;
+
 /** Logging parameters. */
 static uint32_t      g_cHistory = 10;                   /* Enable log rotation, 10 files. */
@@ -280,5 +283,5 @@
             break;
         case AUTOSTARTLOGTYPE_VERBOSE:
-            if (!g_fVerbose)
+            if (!g_cVerbosity)
                 return;
             wType = EVENTLOG_INFORMATION_TYPE;
@@ -474,5 +477,4 @@
      * Parse the arguments.
      */
-    bool fVerbose = false;
     const char *pszUser = NULL;
     static const RTGETOPTDEF s_aOptions[] =
@@ -490,5 +492,5 @@
         {
             case 'v':
-                fVerbose = true;
+                g_cVerbosity++;
                 break;
             case 'u':
@@ -528,5 +530,5 @@
     {
 
-        if (fVerbose)
+        if (g_cVerbosity)
             RTPrintf("The service %s was not installed, nothing to be done.", sServiceName.c_str());
         else
@@ -550,5 +552,4 @@
      * Parse the arguments.
      */
-    bool fVerbose = false;
     const char *pszUser = NULL;
     com::Utf8Str strPwd;
@@ -556,6 +557,8 @@
     static const RTGETOPTDEF s_aOptions[] =
     {
+        /* Common options first. */
         { "--verbose",       'v', RTGETOPT_REQ_NOTHING },
         { "--user",          'u', RTGETOPT_REQ_STRING  },
+        { "--username",      'u', RTGETOPT_REQ_STRING  },
         { "--password-file", 'p', RTGETOPT_REQ_STRING  }
     };
@@ -568,6 +571,7 @@
         switch (ch)
         {
+            /* Common options first. */
             case 'v':
-                fVerbose = true;
+                g_cVerbosity++;
                 break;
             case 'u':
@@ -607,5 +611,5 @@
     int vrc = autostartGetDomainAndUser(pszUser, sDomain, sUserTmp);
     if (RT_FAILURE(vrc))
-        return autostartSvcDisplayError("create - CreateService failed, failed to get domain and user from string %s (%d).\n",
+        return autostartSvcDisplayError("create - Failed to get domain and user from string '%s' (%Rrc)\n",
                                         pszUser, vrc);
     com::Utf8StrFmt sUserFullName("%s\\%s", sDomain.c_str(), sUserTmp.c_str());
@@ -617,5 +621,5 @@
      * Create the service.
      */
-    RTEXITCODE rc = RTEXITCODE_FAILURE;
+    RTEXITCODE rcExit = RTEXITCODE_FAILURE;
     SC_HANDLE hSCM = autostartSvcWinOpenSCManager("create", SC_MANAGER_CREATE_SERVICE); /*SC_MANAGER_ALL_ACCESS*/
     if (hSCM)
@@ -624,5 +628,5 @@
         if (RTProcGetExecutablePath(szExecPath, sizeof(szExecPath)))
         {
-            if (fVerbose)
+            if (g_cVerbosity)
                 RTPrintf("Creating the %s service, binary \"%s\"...\n",
                          sServiceName.c_str(), szExecPath); /* yea, the binary name isn't UTF-8, but wtf. */
@@ -657,17 +661,18 @@
                 /** @todo Set the service description or it'll look weird in the vista service manager.
                  *  Anything else that should be configured? Start access or something? */
-                rc = RTEXITCODE_SUCCESS;
+                rcExit = RTEXITCODE_SUCCESS;
                 CloseServiceHandle(hSvc);
             }
             else
             {
-                DWORD err = GetLastError();
-                switch (err)
+                DWORD const dwErr = GetLastError();
+                switch (dwErr)
                 {
                     case ERROR_SERVICE_EXISTS:
-                        autostartSvcDisplayError("create - The service already exists.\n");
+                        autostartSvcDisplayError("create - The service already exists!\n");
                         break;
                     default:
-                        autostartSvcDisplayError("create - CreateService failed, err=%d.\n", GetLastError());
+                        autostartSvcDisplayError("create - CreateService failed, rc=%Rrc (%#x)\n",
+                                                 RTErrConvertFromWin32(dwErr), dwErr);
                         break;
                 }
@@ -676,7 +681,7 @@
         }
         else
-            autostartSvcDisplayError("create - Failed to obtain the executable path: %d\n", GetLastError());
-    }
-    return rc;
+            autostartSvcDisplayError("create - Failed to obtain the executable path\n");
+    }
+    return rcExit;
 }
 
@@ -766,7 +771,7 @@
         {
             if (dwControl == SERVICE_CONTROL_SHUTDOWN)
-                LogRel(("SERVICE_CONTROL_SHUTDOWN\n"));
+                autostartSvcLogVerbose(1, "SERVICE_CONTROL_SHUTDOWN\n");
             else
-                LogRel(("SERVICE_CONTROL_STOP\n"));
+                autostartSvcLogVerbose(1, "SERVICE_CONTROL_STOP\n");
 
             /*
@@ -793,13 +798,12 @@
              * b/c WinSvc.h defines them in hex
              */
-            LogRel(("Unexpected service control message 0x%RX64\n",
-                    (uint64_t)dwControl));
-            return ERROR_CALL_NOT_IMPLEMENTED;
-    }
-
-    /* not reached */
-}
-
-static RTEXITCODE autostartStartVMs()
+            autostartSvcLogWarning("Unexpected service control message 0x%RX64\n", (uint64_t)dwControl);
+            break;
+    }
+
+    return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+static RTEXITCODE autostartStartVMs(void)
 {
     int rc = autostartSetup();
@@ -919,4 +923,6 @@
 #endif
 
+    DWORD dwErr = ERROR_GEN_FAILURE;
+
     /*
      * Register the control handler function for the service and report to SCM.
@@ -926,5 +932,4 @@
     if (g_hSupSvcWinCtrlHandler)
     {
-        DWORD err = ERROR_GEN_FAILURE;
         if (autostartSvcWinSetServiceStatus(SERVICE_START_PENDING, 3000, NO_ERROR))
         {
@@ -952,5 +957,5 @@
                         {
                             LogFlow(("autostartSvcWinServiceMain: done starting VMs\n"));
-                            err = NO_ERROR;
+                            dwErr = NO_ERROR;
                         }
                         /* No reason to keep started. Shutdown the service*/
@@ -960,6 +965,6 @@
                 else
                 {
-                    err = GetLastError();
-                    autostartSvcLogError("SetServiceStatus failed, err=%u", err);
+                    dwErr = GetLastError();
+                    autostartSvcLogError("SetServiceStatus failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
                 }
 
@@ -972,11 +977,14 @@
         else
         {
-            err = GetLastError();
-            autostartSvcLogError("SetServiceStatus failed, err=%u", err);
-        }
-        autostartSvcWinSetServiceStatus(SERVICE_STOPPED, 0, err);
+            dwErr = GetLastError();
+            autostartSvcLogError("SetServiceStatus failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
+        }
+        autostartSvcWinSetServiceStatus(SERVICE_STOPPED, 0, dwErr);
     }
     else
-        autostartSvcLogError("RegisterServiceCtrlHandlerEx failed, err=%u", GetLastError());
+    {
+        dwErr = GetLastError();
+        autostartSvcLogError("RegisterServiceCtrlHandlerEx failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
+    }
 
     LogFlowFuncLeave();
@@ -985,5 +993,5 @@
 
 /**
- * Handle the 'create' action.
+ * Handle the 'runit' action.
  *
  * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE.
@@ -991,5 +999,5 @@
  * @param   argv    The action argument vector.
  */
-static int autostartSvcWinRunIt(int argc, char **argv)
+static RTEXITCODE autostartSvcWinRunIt(int argc, char **argv)
 {
     int rc;
@@ -1014,5 +1022,4 @@
     if (FAILED(hrc))
         return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM (%Rhrc)!", hrc);
-
     /*
      * Initialize release logging, do this early.  This means command
@@ -1045,5 +1052,5 @@
         }
 
-        rc = com::VBoxLogRelCreate("Autostart",
+        rc = com::VBoxLogRelCreate(AUTOSTART_SERVICE_NAME,
                                    szLogFile,
                                      RTLOGFLAGS_PREFIX_THREAD
@@ -1066,4 +1073,6 @@
     static const RTGETOPTDEF s_aOptions[] =
     {
+        /* Common options first. */
+        { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
         { "--service", 's', RTGETOPT_REQ_STRING },
     };
@@ -1071,20 +1080,24 @@
     const char *pszServiceName = NULL;
     int ch;
-    RTGETOPTUNION Value;
+    RTGETOPTUNION ValueUnion;
     RTGETOPTSTATE GetState;
     RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
-    while ((ch = RTGetOpt(&GetState, &Value)))
+    while ((ch = RTGetOpt(&GetState, &ValueUnion)))
     {
         switch (ch)
         {
+            /* Common options first. */
+            case 'v':
+                g_cVerbosity++;
+                break;
             case 's':
-                pszServiceName = Value.psz;
+                pszServiceName = ValueUnion.psz;
                 try
                 {
-                    g_bstrServiceName = com::Bstr(Value.psz);
+                    g_bstrServiceName = com::Bstr(ValueUnion.psz);
                 }
                 catch (...)
                 {
-                    autostartSvcLogError("runit failed, service name is not valid utf-8 string or out of memory");
+                    autostartSvcLogError("runit failed, service name is not valid UTF-8 string or out of memory");
                     return RTEXITCODE_FAILURE;
                 }
@@ -1092,9 +1105,5 @@
 
             default:
-                /**
-                 * @todo autostartSvcLogGetOptError is useless as it
-                 * is, should be change after RTGetOptPrintError.
-                 */
-                return autostartSvcLogError("RTGetOpt: %Rrc\n", ch);
+                return autostartSvcDisplayGetOptError("runit", ch, &ValueUnion);
         }
     }
@@ -1106,5 +1115,6 @@
     }
 
-    LogRel(("Starting service %ls\n", g_bstrServiceName.raw()));
+
+    autostartSvcLogInfo("Starting service %ls\n", g_bstrServiceName.raw());
 
     /*
@@ -1123,6 +1133,6 @@
     }
 
-    DWORD err = GetLastError();
-    switch (err)
+    DWORD const dwErr = GetLastError();
+    switch (dwErr)
     {
         case ERROR_FAILED_SERVICE_CONTROLLER_CONNECT:
@@ -1130,5 +1140,5 @@
             break;
         default:
-            autostartSvcLogError("StartServiceCtrlDispatcher failed, err=%u", err);
+            autostartSvcLogError("StartServiceCtrlDispatcher failed, rc=%Rrc (%#x)\n", RTErrConvertFromWin32(dwErr), dwErr);
             break;
     }
@@ -1137,4 +1147,12 @@
 
     return RTEXITCODE_FAILURE;
+}
+
+
+static void autostartSvcShowHeader(void)
+{
+    RTPrintf(VBOX_PRODUCT " VirtualBox Autostart Service Version " VBOX_VERSION_STRING " - r%s\n"
+             "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
+             "All rights reserved.\n\n", RTBldCfgRevisionStr());
 }
 
@@ -1172,8 +1190,5 @@
         RTPrintf("%s\n", VBOX_VERSION_STRING);
     else
-        RTPrintf("VirtualBox Autostart Service Version %s\n"
-                 "(C) 2012 Oracle Corporation\n"
-                 "All rights reserved.\n",
-                 VBOX_VERSION_STRING);
+        autostartSvcShowHeader();
     return RTEXITCODE_SUCCESS;
 }
@@ -1187,22 +1202,34 @@
 static RTEXITCODE autostartSvcWinShowHelp(void)
 {
-    RTPrintf(VBOX_PRODUCT " VirtualBox Autostart Service Version " VBOX_VERSION_STRING " - r%s\n"
-             "(C) " VBOX_C_YEAR " " VBOX_VENDOR "\n"
-             "All rights reserved.\n\n", RTBldCfgRevisionStr());
+    autostartSvcShowHeader();
+
+    const char *pszExe = RTPathFilename(RTProcExecutablePath());
 
     RTPrintf("Usage:\n"
              "\n"
-             "VBoxAutostartSvc\n"
-             "      Runs the service.\n"
-             "VBoxAutostartSvc <version|-v|--version> [-brief]\n"
-             "      Displays the version.\n"
-             "VBoxAutostartSvc <help|-?|-h|--help> [...]\n"
-             "      Displays this help screen.\n"
+             "%s [global-options] [command] [command-options]\n"
              "\n"
-             "VBoxAutostartSvc <install|/RegServer|/i>\n"
-             "      Installs the service.\n"
-             "VBoxAutostartSvc <uninstall|delete|/UnregServer|/u>\n"
-             "      Uninstalls the service.\n"
-             );
+             "Global options:\n"
+             "  <help|-?|-h|--help> [...]\n"
+             "    Displays this help screen.\n"
+             "  <version|-v|--version> [-brief]\n"
+             "    Displays the version.\n"
+             "\n"
+             "No command given:\n"
+             "  Runs the service.\n"
+             "  --service <name>\n"
+             "    Specifies the service name to run.\n"
+             "\n"
+             "Command </i|install|/RegServer> --user <username> --password-file <...>\n"
+             "  Installs the service.\n"
+             "Options:\n"
+             "  --user <username>\n"
+             "    Specifies the user name the service should use for installation.\n"
+             "  --password-file <path/to/file>\n"
+             "    Specifies the file for user password to use for installation.\n"
+             "\n"
+             "Command </u|uninstall|delete|/UnregServer>\n"
+             "  Uninstalls the service.\n",
+             pszExe);
     return RTEXITCODE_SUCCESS;
 }
Index: trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart.h
===================================================================
--- trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart.h	(revision 95099)
+++ trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart.h	(revision 95103)
@@ -198,16 +198,18 @@
  * Logs a verbose message to the appropriate system log.
  *
- * @param   pszFormat   The log string. No trailing newline.
- * @param   ...         Format arguments.
- */
-DECLHIDDEN(void) autostartSvcLogVerboseV(const char *pszFormat, va_list va);
+ * @param   cVerbosity  Verbosity level when logging should happen.
+ * @param   pszFormat   The log string. No trailing newline.
+ * @param   ...         Format arguments.
+ */
+DECLHIDDEN(void) autostartSvcLogVerboseV(unsigned cVerbosity, const char *pszFormat, va_list va);
 
 /**
  * Logs a verbose message to the appropriate system log.
  *
- * @param   pszFormat   The log string. No trailing newline.
- * @param   ...         Format arguments.
- */
-DECLHIDDEN(void) autostartSvcLogVerbose(const char *pszFormat, ...);
+ * @param   cVerbosity  Verbosity level when logging should happen.
+ * @param   pszFormat   The log string. No trailing newline.
+ * @param   ...         Format arguments.
+ */
+DECLHIDDEN(void) autostartSvcLogVerbose(unsigned cVerbosity, const char *pszFormat, ...);
 
 /**
Index: trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStart.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStart.cpp	(revision 95099)
+++ trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStart.cpp	(revision 95103)
@@ -33,4 +33,6 @@
 
 #include "VBoxAutostart.h"
+
+extern unsigned g_cVerbosity;
 
 using namespace com;
@@ -72,5 +74,5 @@
     if (uStartupDelay)
     {
-        autostartSvcLogVerbose("Delay starting for %d seconds ...\n", uStartupDelay);
+        autostartSvcLogVerbose(1, "Delaying start for %RU32 seconds ...\n", uStartupDelay);
         vrc = RTThreadSleep(uStartupDelay * 1000);
     }
@@ -137,5 +139,5 @@
                 if ((*it).uStartupDelay > uDelayCurr)
                 {
-                    autostartSvcLogVerbose("Delay starting of the next VMs for %d seconds ...\n",
+                    autostartSvcLogVerbose(1, "Delaying start of the next VMs for %ul seconds ...\n",
                                            (*it).uStartupDelay - uDelayCurr);
                     RTThreadSleep(((*it).uStartupDelay - uDelayCurr) * 1000);
@@ -150,5 +152,5 @@
                 if (SUCCEEDED(rc) && !progress.isNull())
                 {
-                    autostartSvcLogVerbose("Waiting for VM \"%ls\" to power on...\n", (*it).strId.raw());
+                    autostartSvcLogVerbose(1, "Waiting for VM '%ls' to power on...\n", (*it).strId.raw());
                     CHECK_ERROR(progress, WaitForCompletion(-1));
                     if (SUCCEEDED(rc))
@@ -170,5 +172,5 @@
                                 }
                                 else
-                                    autostartSvcLogVerbose("VM \"%ls\" has been successfully started.\n", (*it).strId.raw());
+                                    autostartSvcLogVerbose(1, "VM '%ls' has been successfully started.\n", (*it).strId.raw());
                             }
                         }
Index: trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartUtils.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartUtils.cpp	(revision 95099)
+++ trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartUtils.cpp	(revision 95103)
@@ -35,4 +35,6 @@
 
 using namespace com;
+
+extern unsigned g_cVerbosity;
 
 DECLHIDDEN(const char *) machineStateToName(MachineState_T machineState, bool fShort)
@@ -117,24 +119,25 @@
 }
 
-DECLHIDDEN(void) autostartSvcLogVerboseV(const char *pszFormat, va_list va)
-{
-    if (*pszFormat)
-    {
-        char *pszMsg = NULL;
-        if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
-        {
-            autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_VERBOSE);
-            RTStrFree(pszMsg);
-        }
-        else
-            autostartSvcOsLogStr(pszFormat, AUTOSTARTLOGTYPE_VERBOSE);
-    }
-}
-
-DECLHIDDEN(void) autostartSvcLogVerbose(const char *pszFormat, ...)
-{
-    va_list va;
-    va_start(va, pszFormat);
-    autostartSvcLogVerboseV(pszFormat, va);
+DECLHIDDEN(void) autostartSvcLogVerboseV(unsigned cVerbosity, const char *pszFormat, va_list va)
+{
+    AssertPtrReturnVoid(pszFormat);
+
+    if (g_cVerbosity < cVerbosity)
+       return;
+
+    char *pszMsg = NULL;
+    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
+    {
+        RTPrintf("%s", pszMsg);
+        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_VERBOSE);
+        RTStrFree(pszMsg);
+    }
+}
+
+DECLHIDDEN(void) autostartSvcLogVerbose(unsigned cVerbosity, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    autostartSvcLogVerboseV(cVerbosity, pszFormat, va);
     va_end(va);
 }
@@ -142,15 +145,20 @@
 DECLHIDDEN(void) autostartSvcLogWarningV(const char *pszFormat, va_list va)
 {
-    if (*pszFormat)
-    {
-        char *pszMsg = NULL;
-        if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
-        {
-            autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_WARNING);
-            RTStrFree(pszMsg);
-        }
-        else
-            autostartSvcOsLogStr(pszFormat, AUTOSTARTLOGTYPE_WARNING);
-    }
+    AssertPtrReturnVoid(pszFormat);
+
+    char *pszMsg = NULL;
+    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
+    {
+        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_WARNING);
+        RTStrFree(pszMsg);
+    }
+}
+
+DECLHIDDEN(void) autostartSvcLogWarning(const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    autostartSvcLogWarningV(pszFormat, va);
+    va_end(va);
 }
 
@@ -165,23 +173,13 @@
 DECLHIDDEN(void) autostartSvcLogInfoV(const char *pszFormat, va_list va)
 {
-    if (*pszFormat)
-    {
-        char *pszMsg = NULL;
-        if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
-        {
-            autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_INFO);
-            RTStrFree(pszMsg);
-        }
-        else
-            autostartSvcOsLogStr(pszFormat, AUTOSTARTLOGTYPE_INFO);
-    }
-}
-
-DECLHIDDEN(void) autostartSvcLogWarning(const char *pszFormat, ...)
-{
-    va_list va;
-    va_start(va, pszFormat);
-    autostartSvcLogWarningV(pszFormat, va);
-    va_end(va);
+    AssertPtrReturnVoid(pszFormat);
+
+    char *pszMsg = NULL;
+    if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1)
+    {
+        RTPrintf("%s", pszMsg);
+        autostartSvcOsLogStr(pszMsg, AUTOSTARTLOGTYPE_INFO);
+        RTStrFree(pszMsg);
+    }
 }
 
@@ -205,5 +203,5 @@
 DECLHIDDEN(RTEXITCODE) autostartSvcDisplayErrorV(const char *pszFormat, va_list va)
 {
-    RTStrmPrintf(g_pStdErr, "VBoxSupSvc error: ");
+    RTStrmPrintf(g_pStdErr, "Error: ");
     RTStrmPrintfV(g_pStdErr, pszFormat, va);
     Log(("autostartSvcDisplayErrorV: %s", pszFormat)); /** @todo format it! */
