+ Post New Thread
Results 1 to 7 of 7
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 ...
  1. #1
    AJWhite1970's Avatar
    Join Date
    Sep 2012
    Location
    Wiltshire
    Posts
    278
    Thank Post
    63
    Thanked 70 Times in 53 Posts
    Rep Power
    15

    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

  2. #2
    ricki's Avatar
    Join Date
    Jul 2005
    Location
    uk
    Posts
    1,466
    Thank Post
    20
    Thanked 164 Times in 157 Posts
    Rep Power
    51
    HI

    Can you not used scheduled tasks. You can do this in gpo.

    Richard

  3. Thanks to ricki from:

    AJWhite1970 (14th March 2013)

  4. #3
    AJWhite1970's Avatar
    Join Date
    Sep 2012
    Location
    Wiltshire
    Posts
    278
    Thank Post
    63
    Thanked 70 Times in 53 Posts
    Rep Power
    15
    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

  5. #4
    cromertech's Avatar
    Join Date
    Dec 2007
    Location
    Cromer by the coast
    Posts
    731
    Thank Post
    177
    Thanked 109 Times in 97 Posts
    Rep Power
    53
    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

  6. Thanks to cromertech from:

    AJWhite1970 (14th March 2013)

  7. #5

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,182
    Thank Post
    1,285
    Thanked 1,029 Times in 729 Posts
    Rep Power
    658
    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.

  8. Thanks to LosOjos from:

    AJWhite1970 (14th March 2013)

  9. #6
    AJWhite1970's Avatar
    Join Date
    Sep 2012
    Location
    Wiltshire
    Posts
    278
    Thank Post
    63
    Thanked 70 Times in 53 Posts
    Rep Power
    15
    Thanks to everyone for their help, epically @LosOjos

    I now have this working exactly how I need it
    Andrew

  10. #7

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,182
    Thank Post
    1,285
    Thanked 1,029 Times in 729 Posts
    Rep Power
    658
    Quote Originally Posted by AJWhite1970 View Post
    Thanks to everyone for their help, epically @LosOjos

    I now have this working exactly how I need it
    Andrew
    Happy to help

SHARE:
+ Post New Thread

Similar Threads

  1. MRBS: how to disallow booking for a particular time of the day
    By nikon in forum Network and Classroom Management
    Replies: 4
    Last Post: 18th May 2011, 09:01 AM
  2. Replies: 9
    Last Post: 6th October 2010, 03:54 PM
  3. Replies: 2
    Last Post: 9th May 2008, 08:56 AM
  4. Replies: 9
    Last Post: 10th May 2007, 10:13 AM
  5. IE6 trys to run an ISP setup on startup
    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
  •