Jump to content

Script wanted to run an .exe between specific times of the day


Recommended Posts

Posted

Hi. Firstly, I'm not a vbs coder so if this is blindingly simple then I apologize in advance ;)

 

I'm looking to add to my students simple vbs login script so that I can run an .exe file but only if the time is between 08:00 and 15:40.

 

So basically if time >= 08:00 or time <=15:40 then run myfile.exe else end

 

Any help would be greatly appreciated.

 

Regards

Andrew

Posted (edited)

You can use a scheduled task for this if it is only for your students but it will probably need to be setup to run at log on and then repeated every hour until log off. If it's absolutely necessary to run it between those times you can create an item level target for a time frame. You can copy and paste the following into the Group Policy Preferences scheduled task dialog and edit as needed. Remember to edit the author section in red to your user before pasting.





[color=#ff0000]{domain}\{user}[/color]
Run a file at logon during a certain time of day



%LogonDomain%\%LogonUser%
InteractiveToken
LeastPrivilege




PT5M
PT1H
false
false

IgnoreNew
false
false
false
false
true
false
PT0S
7



true
%LogonDomain%\%LogonUser%

PT1H
P1D
false


           myfile.exe
           

Edited by cromertech
reformat horrible XML
  • Thanks 1
Posted (edited)

Something like this as a logon script should do it:

 

On Error Resume Next
DIM objShell
DIM startTime
DIM endTime
DIM curTime

' Set start time of the script.
startTime=FormatDateTime("08:00", 4)

' Set end time of the script.
endTime=FormatDateTime("15:40", 4)

'current time
curTime=FormatDateTime(Time, 4)

IF curTime>=startTime AND curTime<=endTime THEN
   SET objShell = CreateObject("WScript.Shell")    
   
   ' Insert here your Application to run
   objShell.Run "%windir%\notepad.exe" 

   SET objShell=Nothing
END IF

 

EDIT: changed the code to simplify and remove a glaring logic error!

Edited by LosOjos
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...