need simple standalone batch script to create cmd shell, run exe, sleep 6 seconds

Hi SysAdmins & VBScript Folks,

Thank you for a moment of your time.

I'm running a program called SyncBackSE, which runs some very cool FTP stuff as a background task every 6 seconds while I'm logged on.

The problem is that when I log off, the background task will no longer run, and the smallest possible increment for scheduling tasks in Windows Task Manager is one minute.

I need a very simple standalone VBScript (not embedded in an asp or other page), which will run on a server I have.

Ultimately, I need to run this line:
"C:\Program Files\2BrightSparks\SyncBackSE\SyncBackSE.exe" -m "funny name goes here"

I need to run the above line every 6 seconds, for 24 hrs a day, 7 days a week, 365 days a year.

The solution I've devised is to create a Windows task scheduler task that kicks off a vbscript every 1 minute, repeatedly, indefinitely, daily.

It will kick off the vbscript, and the vbscript will execute the line I've pasted above, with the .exe in it.
This vbscript should run this line once, then sleep for 6 seconds, and then do it again for 10 loops (probably do while) ..... in other words, 10 times per minute, or once every 6 seconds.

This way, if the script gets hung for any reason, it will be restarted again once every minute, when the task manager kicks it off.  (I'm wondering if this is the most reliable way to keep this going without hickups or hangs).

Obviously, I want this to run all the time, not just when I'm logged on as Admin.

Don't forget to escape any characters (quotes?) that may need it in the execution of the binary file (you can probably substitute notepad.exe or some other binary since you may not want to download and test with SyncBackSE).

PLEASE provide me a very simple vbscript that WORKS, for 500 easy pts.  

Thanks so much!,
~k


create command shell and supress debugging/errors/popups
 
i=1
Do While i < 11
     "C:\Program Files\2BrightSparks\SyncBackSE\SyncBackSE.exe" -m "funny name goes here"
     WScript.Sleep 6
      i = i + 1
Loop
clean up and exit

Open in new window

ksuchyAsked:
Who is Participating?
 
ltlbearand3Commented:
vbScript keeps going through the code while your wsobject.run line is running.  To make it wait for the completion of the .run command you need to assign it to a variable.

Try the following

set wsobject = wscript.createobject("wscript.shell")
i=1
do while i<11
  strEXE = """C:\Program Files\2BrightSparks\SyncBackSE\SyncBackSE.exe"" -m ""FTPWebcam"""
  strReturn = wsobject.run(strEXE,0,TRUE)
  wscript.sleep 6000
  i=i+1
loop

Open in new window

0
 
BobTheViolentCommented:
Pretty easy,

Try this one.  Our server runs something like this during times of the day.

The sleep value is in milliseconds.  1000 = 1 second

Is that what you needed?

THIS GOES IN A .VBS FILE NAMED LOOP.VBS FOR EXAMPLE
 
set wsobject = wscript.createobject("wscript.shell")
 
do while 1=1
  wsobject.run "somefilename.exe",0,TRUE
  wscript.sleep 6000
loop
 
 
THIS GOES IN A .BAT FILE IN THE SAME DIRECTORY
cscript loop.vbs %1

Open in new window

0
 
ksuchyAuthor Commented:
Hi Bob,

Thank you for your help.  

What you have included here is a good start, but incomplete and it does not do everything I've asked.  I'm asking for one simple (aka, "easy") script, which does everything I've asked, and has already been debugged and tested to work, and accomplishes everything I've asked, including escaping quotes in the path+switches.  Please if possible, carefully review my original post which includes full details and requirements.

Kind Regards,
~k

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
ksuchyAuthor Commented:
The below code actually works, but only once.
When I have it scheduled to repeat every 1 minute (duration set to 2 minutes, because MS apparently requires duration to be longer than repetition interval), then it kicks off and goes through the loop 10 times, but then that's it.

Not sure why.
Any ideas?
set wsobject = wscript.createobject("wscript.shell")
i=1
do while i<11
  strEXE = """C:\Program Files\2BrightSparks\SyncBackSE\SyncBackSE.exe"" -m ""FTPWebcam"""
  wsobject.run strEXE,0,TRUE
  wscript.sleep 6000
  i=i+1
loop

Open in new window

0
 
ChizlCommented:
You can also use:

Set process = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_process")
strUpdateCommand = "myexe.exe parm1 parm2"
result = process.create(strCommand,Null,Null,processid)
If result <> 0 Then
    MsgBox "Failed to process"
End If
0
 
ksuchyAuthor Commented:
Thanks :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.