return MessageBox(0, _T("The message which was supposed to go here is missing!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
\r
- TCHAR blurb[512];\r
+ TCHAR blurb[1024];\r
va_start(arg, id);\r
if (_vsntprintf_s(blurb, _countof(blurb), _TRUNCATE, format, arg) < 0) {\r
va_end(arg);\r
LocalFree(format);\r
- return MessageBox(0, _T("the message which was supposed to go here is too big!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
+ return MessageBox(0, _T("The message which was supposed to go here is too big!"), NSSM, MB_OK | MB_ICONEXCLAMATION);\r
}\r
va_end(arg);\r
\r
\r
/* How to use me correctly */\r
int usage(int ret) {\r
- print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
+ if (GetConsoleWindow()) print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
+ else popup_message(MB_OK, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_DATE);\r
return(ret);\r
}\r
\r
FreeSid(AdministratorsGroup);\r
}\r
\r
+/* See if we were launched from a console window. */\r
+static void check_console() {\r
+ /* If we're running in a service context there will be no console window. */\r
+ HWND console = GetConsoleWindow();\r
+ if (! console) return;\r
+\r
+ unsigned long pid;\r
+ if (! GetWindowThreadProcessId(console, &pid)) return;\r
+\r
+ /*\r
+ If the process associated with the console window handle is the same as\r
+ this process, we were not launched from an existing console. The user\r
+ probably double-clicked our executable.\r
+ */\r
+ if (GetCurrentProcessId() != pid) return;\r
+\r
+ /* We close our new console so that subsequent messages appear in a popup. */\r
+ FreeConsole();\r
+}\r
+\r
int _tmain(int argc, TCHAR **argv) {\r
+ check_console();\r
+\r
/* Remember if we are admin */\r
check_admin();\r
\r