?
Solved

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

Posted on 2008-11-04
6
Medium Priority
?
2,336 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:ksuchy
6 Comments
 
LVL 2

Assisted Solution

by:BobTheViolent
BobTheViolent earned 400 total points
ID: 22878762
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
 

Author Comment

by:ksuchy
ID: 22879311
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
 

Author Comment

by:ksuchy
ID: 22880974
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 800 total points
ID: 22881912
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
 
LVL 4

Assisted Solution

by:Chizl
Chizl earned 800 total points
ID: 22900749
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
 

Author Closing Comment

by:ksuchy
ID: 31513190
Thanks :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question