Scripts Thread, Script wanted to run an .exe between specific times of the day in Coding and Web Development; Hi. Firstly, I'm not a vbs coder so if this is blindingly simple then I apologize in advance
I'm looking ...
-
14th March 2013, 09:10 AM #1 Script wanted to run an .exe between specific times of the day
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
-
-
IDG Tech News
-
14th March 2013, 10:40 AM #2 HI
Can you not used scheduled tasks. You can do this in gpo.
Richard
-
Thanks to ricki from:
AJWhite1970 (14th March 2013)
-
14th March 2013, 10:51 AM #3 I don't think so. When I looked I could either run a task on login or at a scheduled time but I couldn't see how to schedule it between two set times.
Andrew
-
-
14th March 2013, 11:21 AM #4 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.
Code:
<?xml version="1.0"?>
<TaskV2 clsid="{D8896631-B747-47a7-84A6-C155337F3BC8}" name="Log on run myfile.exe between 08:00 and 15:40" image="1" changed="2013-03-14 11:19:00" uid="{CEB35AE5-92A0-4EFF-84B9-5E35C7DFBB4F}" userContext="1" removePolicy="1">
<Properties action="R" name="Log on run myfile.exe between 08:00 and 15:40" runAs="%LogonDomain%\%LogonUser%" logonType="InteractiveToken">
<Task version="1.2">
<RegistrationInfo>
<Author>{domain}\{user}</Author>
<Description>Run a file at logon during a certain time of day</Description>
</RegistrationInfo>
<Principals>
<Principal id="Author">
<UserId>%LogonDomain%\%LogonUser%</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<IdleSettings>
<Duration>PT5M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<AllowStartOnDemand>false</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Triggers>
<LogonTrigger>
<Enabled>true</Enabled>
<UserId>%LogonDomain%\%LogonUser%</UserId>
<Repetition>
<Interval>PT1H</Interval>
<Duration>P1D</Duration>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
</LogonTrigger>
</Triggers><Actions><Exec><Command>myfile.exe</Command></Exec>
</Actions></Task></Properties><Filters><FilterTime bool="AND" not="0" begin="08:00:00" end="15:40:00"/></Filters></TaskV2>
Last edited by cromertech; 14th March 2013 at 11:37 AM.
Reason: reformat horrible XML
-
Thanks to cromertech from:
AJWhite1970 (14th March 2013)
-
14th March 2013, 11:26 AM #5 Something like this as a logon script should do it:
Code:
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!
Last edited by LosOjos; 14th March 2013 at 11:41 AM.
-
Thanks to LosOjos from:
AJWhite1970 (14th March 2013)
-
14th March 2013, 01:15 PM #6 Thanks to everyone for their help, epically @LosOjos
I now have this working exactly how I need it
Andrew
-
-
14th March 2013, 01:26 PM #7 
Originally Posted by
AJWhite1970
Thanks to everyone for their help, epically @
LosOjos
I now have this working exactly how I need it
Andrew
Happy to help
-
SHARE: 
Similar Threads
-
By nikon in forum Network and Classroom Management
Replies: 4
Last Post: 18th May 2011, 09:01 AM
-
By FN-GM in forum Scripts
Replies: 9
Last Post: 6th October 2010, 03:54 PM
-
By plexer in forum Our Advertisers
Replies: 2
Last Post: 9th May 2008, 08:56 AM
-
By sidewinder in forum Scripts
Replies: 9
Last Post: 10th May 2007, 10:13 AM
-
By pmassingham in forum Windows
Replies: 1
Last Post: 23rd March 2006, 10:20 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules