Putty – Automatically Close Window on Exit from Command Line

putty

I am trying to make a headless machine that automatically runs putty on startup from a script and auto relaunches should the program close.

Whilst this technically is working fine in most situations, if there are network issues, putty will just hang with a popup saying that it has been disconnected.

I have seen the option "close window on Exit" and I know this is what I need, but, I can only do this fro the window – I have not found a way to change this setting from the command line.

Does anyone know if this is possible and what to set… or if it is just possible to change the defaults as this is all that will be run on this machine?

Best Answer

The best solution would be to create a custom session in PuTTY (with the "Close window on exit" setting changed) and load that session via the command line, but if you don't have access to the GUI, that's not easy. However, I don't know of any way to specify individual settings via the command line.

If you can edit the registry, however, you can create a session by creating a new key in

HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

where you can then add values corresponding with the session settings in the GUI. So, if you want to have the window always close on exit, you would add a DWORD value named CloseOnExit containing the value 2. Everything else not specified will stay as the default.

You would then add

-load "session name"

to your command line string, where "session name" is the name of the key you created. Put whatever other command line options after that (such as server, login name, password, etc.) and you're all set.

I've tested this myself, but it's still prudent to back up your registry before any manual editing.

Alternately, there are forks of PuTTY (such as PuTTY Tray) that feature automatic reconnection after an interruption, though I can't vouch for how well they work.

Related Question