Is there a way to make putty automatically "close window on exit" from the command line?

7

1

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?

William Hilsum

Posted 2012-05-29T16:43:34.100

Reputation: 111 572

Answers

5

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.

clpo13

Posted 2012-05-29T16:43:34.100

Reputation: 536

This worked brilliantly! I didn't know it was possible to launch a session like that! – William Hilsum – 2012-05-30T12:47:18.070

1

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")
sleep(100)
WinClose("PuTTY (inactive)","")

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

jftuga

Posted 2012-05-29T16:43:34.100

Reputation: 2 877

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 – 2012-05-29T17:21:58.357

0

I know I am late to the game, but you could also use putty's plink.exe. It takes the same parameters as putty, but runs in-line much like the ssh command. It also blocks processing and returns a failure status, which could be very useful for a failed connection amidst a bunch of commands.

Cory-G

Posted 2012-05-29T16:43:34.100

Reputation: 141