Take the 2-minute tour ×

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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


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.

share|improve this answer
This worked brilliantly! I didn't know it was possible to launch a session like that! –  William Hilsum May 30 '12 at 12:47

When you get this error:

putty error

then you can write an AutoIt Script that waits for this window to appear and acknowledge it:

$title = "PuTTY Fatal Error"
WinWaitActive( $title )
ControlClick($title,"", "Button1", "primary")
WinClose("PuTTY (inactive)","")

You can also compile the script to a small, standalone .exe file. Put this into your batch file before starting PuTTY.

share|improve this answer
Unfortunately, this will not work as I launch putty via a command script that runs even if a user is not logged in.. I can't see the GUI even after logging in. –  William Hilsum May 29 '12 at 17:21

Your Answer


