Forum Home
Press F1
 
Thread ID: 100833 2009-06-22 05:22:00 Batch file to keep program running nofam (9009) Press F1
Post ID Timestamp Content User
784521 2009-06-22 05:22:00 Hi all,

Can anyone help me with a batch file - what I'm doing is using PuTTY to telnet into our PABX and record call information into a log file. The session is running on an Administrator login on a WinServ 2003 machine, but for no good reason (that I can see), it mysteriously disappears.

What I want is a batch file that basically says:


If [PuTTY session] is running, wait xxx seconds then check again
else run C:\putty.exe

i.e. check to see it's running, and if it is, wait a few minutes and then check again. If it's not running, restart it.

Is this possible?

:thumbs:
nofam (9009)
784522 2009-06-22 09:52:00 Not a batch file. vb script file

sProcessName = "<PUT PROCESS NAME HERE>"

sComputer = "." ' use "." for local computer
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

Set oShell = CreateObject("WScript.Shell")

' go into eternal loop
Do
Set colProcessList = oWmi.ExecQuery _
("Select * from Win32_Process Where Name = '" & sProcessName & "'")

If colProcessList.Count = 0 Then
oShell.Run "<ENTER PATH AND PROGRAM HERE>" & sProcessName, 1, False
End If

WScript.Sleep 30000 ' wait 30 secounds before trying again
maybe a start to what you want I use it for a simular purpose
beama (111)
784523 2009-06-22 09:59:00 forgot mention, I think that come from tech net beama (111)
784524 2009-06-22 21:38:00 Awesome - thanks a million Beama!

Sorry for such a silly question, but how do I actually run a vb script? :o
nofam (9009)
784525 2009-06-22 21:49:00 Putty has a setting under "Connection" for keeping the session active - have you got this set ?

You can control the number of seconds between keepalive packets and there are a few other options that may be useful.
decibel (11645)
784526 2009-06-22 21:56:00 Sorry, is it Putty that's failing or is it the telnet session that's failing ? decibel (11645)
784527 2009-06-22 22:37:00 Sorry, is it Putty that's failing or is it the telnet session that's failing ?

It's the PuTTY session itself - just disappears altogether


Putty has a setting under "Connection" for keeping the session active - have you got this set ?

You can control the number of seconds between keepalive packets and there are a few other options that may be useful.

No I completely forgot about that setting to be honest!! I'll give it a shot, thanks Decibel!! :thumbs:
nofam (9009)
784528 2009-06-23 00:06:00 Awesome - thanks a million Beama!

Sorry for such a silly question, but how do I actually run a vb script? :o

Paste in notepad and save with .vbs extension
Blam (54)
784529 2009-06-23 07:30:00 Paste in notepad and save with .vbs extension

OK. But how is the script actually run?
Sweep (90)
784530 2009-06-23 08:28:00 OK. But how is the script actually run?

All I know is its a "crippled" version of proper VB.

en.wikipedia.org

That explains it all well:)
Blam (54)
1 2