Solved .bat file calls .js file but I want them in a single file

April 29, 2012 at 13:38:27
Specs: Windows 98
Below is a bat file with a delay to keep alive a network connection but it also calls .js file to simulate "enter" on the keyboard. This will keep a network PC from locking me out which would force me to re-log in via CTRL+ALT+DEL within every three minutes. Pinging an IP will not disable the PC from locking but hitting any key will.

Can this be done in a single file, either a .bat or a .js ?
Also, ctrl-C does not exit the bat file. I think I need an IF THEN loop ? or something while pinging to exit if ctrl-C is pressed.

== delay .bat file ====

@echo off
:start
ping -n 1 www.google.com <-- can rem out this line if keepalive is not needed
ping 127.0.0.1 -n 120 > nul
cscript KeepAlive.js
goto start


== KeepAlive .js file ====

var WshShell = WScript.CreateObject("WScript.Shell");
WScript.Sleep(2000); // wait 2 sec.
WshShell.SendKeys("{ }"); // spacebar


See More: .bat file calls .js file but I want them in a single file

Report •


#1
April 30, 2012 at 09:55:14
Specs: Windows 98
Does this really run on a Win98 box?

Can this be done in a single file, either a .bat or a .js ?
It could be done with .js or .vbs if you prefer, but you'd have to run the script though cscript. So you write a .bat or make a shortcut to do it for you, and you're back up to 2 files.

How To Ask Questions The Smart Way


Report •

#2
April 30, 2012 at 14:46:40
Yes. I'm running it on win 98

Report •

#3
May 1, 2012 at 10:39:40
✔ Best Answer
I have no way of testing this in Win98, so maybe this works. You'll need to call this from cscript, and not wscript.
var WshShell = WScript.CreateObject("WScript.Shell");
while(1) {
  WScript.Sleep(2000); // wait 2 sec.
  WshShell.SendKeys("{ }"); // spacebar
  WshShell.Run("ping -n 1 www.google.com", 0, true);
}

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
May 1, 2012 at 14:22:55
Thanks. This does work in win 98.
Actually the bat file isnt needed for your script. (I just double click on the .js file containing your WH script). But the bat file makes it easier to exit. So, again Thanks. This is perfect. :)

Report •

#5
Report •


Ask Question