Jump to content

Timer when to start or stop a system by system time


Bea
 Share

Recommended Posts

Hallo i try to make a script for my VServer, which starts anothr script for an specific time. For example if the System hits 8:00 it starts the script, if the script hist 16:00 its stops. This all must be in a loop, but the problem is now the script opens not once, it opens a hundret times when the timer hits 8:00 :S

 

pls help a gril :)

#include <Date.au3>


While 1

If _NowTime(5) = "17:29:00" Then
      Run("notepad.exe")

EndIf

If _NowTime(5) = "17:30:00" Then
      ProcessClose("notepad.exe")
EndIf

WEnd

 

Link to comment
Share on other sites

Time is counted in milliseconds, so "if" is true from 17:29:00.000 to 17:29:00.999, if each command takes 0.1 sec (totally arbitrary number) it can easily start ~10 notepad.exe instances.

To solve this make sure it's true only once, with something like

#include <Date.au3>

$running = False
While 1

If _NowTime(5) = "17:29:00" And Not $running Then
    Run("notepad.exe")
    $running = True
EndIf

If _NowTime(5) = "17:30:00" And $running Then
    ProcessClose("notepad.exe")
    $running = False
EndIf

WEnd

 

Link to comment
Share on other sites

21 hours ago, Bea said:

if the System hits 8:00 it starts the script, if the script hist 16:00 its stops

 

#include <Date.au3>


While 1

If _NowTime(5) = "17:29:00" Then
      Run("notepad.exe")

EndIf

If _NowTime(5) = "17:30:00" Then
      ProcessClose("notepad.exe")
EndIf

WEnd

 

I've not tested, but you can;

#include <Date.au3>

While 1

If _NowTime(3) = "8:05" And Not ProcessExists("notepad.exe") Then

Run("notepad.exe")

EndIf

Sleep(1000)

If _NowTime(3) >= "16:00" And ProcessExists("notepad.exe) Then

ProcessClose("notepad.exe")

ExitLoop

EndIf

WEnd

Edited by Colduction
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...