Bea Posted March 22, 2019 Posted March 22, 2019 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
Dionysis Posted March 22, 2019 Posted March 22, 2019 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
RestrictedUser Posted March 23, 2019 Posted March 23, 2019 (edited) 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 March 23, 2019 by Colduction
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now