Przeglądaj źródła

Disable console window's close menu item.

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.
Iain Patterson 10 lat temu
rodzic
commit
a8cb4778bd
2 zmienionych plików z 6 dodań i 0 usunięć
  1. 1 0
      README.txt
  2. 5 0
      console.cpp

+ 1 - 0
README.txt

@@ -681,6 +681,7 @@ and/or stderr which attempt to read from stdin would fail.
 Thanks to Czenda Czendov for help with Visual Studio 2013 and Server 2012R2.
 Thanks to Alessandro Gherardi for reporting and draft fix of the bug whereby
 the second restart of the application would have a corrupted environment.
+Thanks to Hadrien Kohl for suggesting to disable the console window's menu.
 
 Licence
 -------

+ 5 - 0
console.cpp

@@ -48,6 +48,11 @@ void alloc_console(nssm_service_t *service) {
 
   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);