As a Linux sysadmin, I spend hours per day using the PuTTY SSH terminal emulator. It is a small, fast and lightweight application that works well and requires little attention.
PuTTY only has one annoyance that I’ve noticed: if a connection fails or drops, it puts up a modal “PuTTY Fatal Error” dialog. If I have many connections up and then hibernate, lose connectivity, or take the laptop to a new location, they all break. I would like to just right-click PuTTY in the Taskbar and choose “Close all windows” but that does not work because of the modal dialogs. I have to click on each session, dismiss the dialog, and close the window.
Since PuTTY is a small and lightweight open-source application, this nuisance should be easily fixable. The error should display in the PuTTY window itself rather than in a pop-up dialog.
My first problem was to get a build environment up. I brought up a temporary Windows Server 2019 Base at AWS and downloaded: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 onto it. I only installed the C++ build tools. Use the \\tsclient\c path to access local files from the VM, assuming you enabled drive sharing under Remote Desktop Connection/Local Resources.
PuTTY source is here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html under Windows source archive.
Using PuTTY 0.73 source, the code change required is in windows\window.c function win_seat_connection_fatal() around line 1196. Here is the change:
/* * Print a message box and close the connection. */ static void win_seat_connection_fatal(Seat *seat, const char *msg) { char *title = dupprintf("%s Fatal Error", appname); win_seat_output(seat,0,"\r\n------------------------------------------------------------------------\r\n",76); win_seat_output(seat,0,title,strlen(title)); win_seat_output(seat,0,": ",2); win_seat_output(seat,0,msg,strlen(msg)); win_seat_output(seat,0,"\r\n",2); // MessageBox(hwnd, msg, title, MB_ICONERROR | MB_OK); sfree(title); if (conf_get_int(conf, CONF_close_on_exit) == FORCE_ON) PostQuitMessage(1); else { queue_toplevel_callback(close_session, NULL); } }
The MessageBox call, which I commented out, generates the modal pop-up. I replaced it with calls to win_seat_output to print to the terminal window instead. That one function is all that has to be changed.
Now to compile it. After installing VC Build Tools and copying the modified PuTTY source under Downloads, I did:
cd c:\Users\Administrator\Downloads\putty\windows "c:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 nmake -f Makefile.vc copy putty.exe \\tsclient\c\bin\
The new PuTTY is now in my local C:\bin directory and is ready to use. Here’s what a disconnect looks like now: