Jump to content
zcwight

End process if not after 5:00

Recommended Posts

zcwight

All I'm after is a script that will continuously check the time, and if a process starts before 5:00, then it will be killed straight away, if its after 5:00,  then it is allowed to run. But on weekends the process is allowed to run at any time.

A script that I could just modify to my needs would be nice, but if someone could point me to the Help File section that will do what I need, that would be better.

Share this post


Link to post
Share on other sites
InunoTaishou

You'll need to register when the process started. I know in powershell you can check when a process started and how long it's been running but idk how to get that data through autoit.

I'd do something like a 2d array that holds the pid and the hour it started.

Use ShellExecute, or Run, to start the process and get the PID of that process.

You can use ProcessExists to check and see if the PID of the process is still running.

Use ProcessClose to force close a program (idk what program you're talking about, there's probably a safer way to close your program that just killing in using ProcessClose)

Share this post


Link to post
Share on other sites
kylomas

zcwight,

What is the start time to not allow a process to run?

E.G. between 8:00AM and 5:00PM

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

zcwight,

In case you return to this thread here is a quick and dirty (and very simple) version of my understanding of your OP...

#include <array.au3>
#include <date.au3>

;    test progs ---------------------------------------------
Run(@ScriptDir & '\test1.exe')
Run(@ScriptDir & '\test2.exe')
;    test progs ---------------------------------------------

Local $aProcessesToMonitor = [ _
        'test1.exe', _
        'test2.exe' _
        ]

Local $sStartHour = '08:00:00'
Local $sEndHour = '17:00:00'

While 1
    If (@WDAY <> 7 And @WDAY <> 1) And ($sStartHour < StringRight(_NowCalc(), 8) And $sEndHour > StringRight(_NowCalc(), 8)) Then
        For $i = 0 To UBound($aProcessesToMonitor) - 1
            $aTmp = ProcessList($aProcessesToMonitor[$i])
            If @error Then ContinueLoop
            For $j = 1 To UBound($aTmp) - 1
                ProcessClose($aTmp[$j][1])
                ConsoleWrite('Closing ' & $aTmp[$j][0] & '[' & $aTmp[$j][1] & ']' & @CRLF)
            Next
        Next
    EndIf
    Sleep(1000)
WEnd

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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

  • Similar Content

    • DynamicRookie
      By DynamicRookie
      Hey There!
       
      So, what i need to do is an app that can read text in a image (I.e. a png that has text saying "This is a png" and return the text to a variable)
      I'm pretty much a newbie on AutoIt, my purpose is doing that but i don't know any function that can

      Any help is much appreciated
    • santoshM
      By santoshM
      How can i exit from a procedure in auto
      Func test() if x=o then     return endif endFunc  
    • Valnurat
      By Valnurat
      Hi
      Small question.
      I trying to find all index in an array with value higher than 7.
      How can that be possible?
    • TrashBoat
      By TrashBoat
      Could someone help me create or give an idea of how to do a incrementing for loop that would do this: https://i.imgur.com/YFUt47H.gifv
      I'm having a hard time figuring it out :S
    • msd1994
      By msd1994
      I have a script that just adds some keyboard shortcuts for things like displaying the current song and artist, moving the window to the side so it won't pop up in my way, and play/pause, next song, previous song (these are the only 3 to still work since they don't need the window handle.)
      In some update recently, Spotify's window class swapped from "[CLASS:SpotifyMainWindow]" to "[CLASS:Chrome_WidgetWin_0]". Using the new class in my controls doesn't seem to work, I've tried getting the window handle from the process handle (_GetHwndFromPID($PID)) but that seems to fail as well.
      Does anybody have some idea of a way I could get this script working again?
       
      edit: seems like discord has the same window class name, so could be some issue with this? Still not sure of a way to solve the issue though, I added a function to get the handle of the active window and can just use that now, but it was able to find it on its own before on spotify startup or script startup which would be preferred.
       
      Thanks!
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.