WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: jkjk12 on June 03, 2015, 12:31:14 PM

Title: run an .EXE at a set time?
Post by: jkjk12 on June 03, 2015, 12:31:14 PM
Using WinBatch can you call a PowerShell script (.ps1 extention) every 12 hours?    Example:  I need to run a PowerShell script at 8:00am and 8:00pm 7 days per week.  Using TimeDelay() won't work for this.  So how do you script that? 
   
Title: Re: run an .EXE at a set time?
Post by: JTaylor on June 03, 2015, 12:37:05 PM
Any reason you wouldn't want to just use Windows Task Scheduler?

Jim
Title: Re: run an .EXE at a set time?
Post by: jkjk12 on June 03, 2015, 12:55:37 PM
Yes I did look at task schedule.  What I am calling has to run interactive.   So it has to run when a user is Logged into the system.   Windows 7 and the newest GPO don't allow you to enter a password anymore.  And if you choose "run whether user is logged on or not" it will not run interactive.   So I want something running in the users context that will in turn kick off our reboot utility ever 12 hours.  And the reboot utility checks the uptime of the system.  If it has been up for more than 7 days it will throw up an interactive dialog that gives the user some options.   
Title: Re: run an .EXE at a set time?
Post by: JTaylor on June 03, 2015, 01:21:23 PM
Will TimeWait() do what you need?

Jim
Title: Re: run an .EXE at a set time?
Post by: jkjk12 on June 03, 2015, 01:37:42 PM
I found that and it should, but it would be crude.   Example:  I have to run it like this:

a=TimeYmdHms( ) ; Gets Current Time
b=TimeAdd(a,"0000:00:00:12:00:00")
TimeWait(b)
Run("\\mgserver\scripts\Tools\RebootTool\Reboot.exe", "")

TimeDelay()

and repeat this code for 7 days worth of running.  I wanted to put the TimeWait() in some type of loop.


Title: Re: run an .EXE at a set time?
Post by: JTaylor on June 03, 2015, 01:57:13 PM
Why not something like:
Code (winbatch) Select

stime = StrSub(TimeYmdHms(),1,10):":08:00:00"

While 1

  TimeWait(stime)
  Run("\\mgserver\scripts\Tools\RebootTool\Reboot.exe", "")
  stime = TimeAdd(stime,"0000:00:00:12:00:00")

EndWhile

Title: Re: run an .EXE at a set time?
Post by: jkjk12 on June 04, 2015, 08:59:31 AM
thanks that look clean.  I will test it out. 
Title: Re: run an .EXE at a set time?
Post by: DAG_P6 on June 19, 2015, 12:30:34 PM
With that option, you can have the login script start it.