We can't trap Control-C in a service context but we can grey out the
close window button on the console window. Doing so goes some way
toward preventing accidental closure.
Thanks Hadrien Kohl.
Thanks to Czenda Czendov for help with Visual Studio 2013 and Server 2012R2.\r
Thanks to Alessandro Gherardi for reporting and draft fix of the bug whereby\r
the second restart of the application would have a corrupted environment.\r
+Thanks to Hadrien Kohl for suggesting to disable the console window's menu.\r
\r
Licence\r
-------\r
AllocConsole();
+ /* Disable accidental closure. */
+ HWND window = GetConsoleWindow();
+ HMENU menu = GetSystemMenu(window, false);
+ EnableMenuItem(menu, SC_CLOSE, MF_GRAYED);
+
/* Set a title like "[NSSM] Jenkins" */
TCHAR displayname[SERVICE_NAME_LENGTH];
unsigned long len = _countof(displayname);