run an .EXE at a set time?

Started by jkjk12, June 03, 2015, 12:31:14 PM

Previous topic - Next topic

jkjk12

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? 
   

JTaylor

Any reason you wouldn't want to just use Windows Task Scheduler?

Jim

jkjk12

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.   

JTaylor

Will TimeWait() do what you need?

Jim

jkjk12

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.



JTaylor

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


jkjk12

thanks that look clean.  I will test it out. 

DAG_P6

With that option, you can have the login script start it.
David A. Gray
You are more important than any technology.