From: Iain Patterson Date: Mon, 14 Apr 2014 18:25:38 +0000 (+0100) Subject: Disable console window's close menu item. X-Git-Tag: v2.22~2 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=a8cb4778bd765c3e3294b18ffe035b5912812bf4;p=nssm.git 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. --- diff --git a/README.txt b/README.txt index b0d32a7..0b44ed4 100644 --- a/README.txt +++ b/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 ------- diff --git a/console.cpp b/console.cpp index 0c7afbe..66c99ea 100644 --- a/console.cpp +++ b/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);