Sign in to follow this  
Followers 0
jefhal

Application killer with timer needs help

7 posts in this topic

If you start this app and then launch Notepad, it is supposed to let Notepad run for 2 minutes and then kill it. However, when it gets to the line called: ";AS SOON AS SCRIPT GETS HERE" the script kills Notepad, even though there is no WinClose statement at that point! I am pulling my hair out on this one.

The point of this app is (similar to Jesse Griffin's Killspace) is to kill apps like AIM when my kids have exceded their allocated time per day. Thanks for the help...

#include <date.au3>

$g_szVersion = "Dadsoft"
$day = _DateToDayValue ( @Year, @Mon, @MDAY )
If WinExists($g_szVersion) Then Exit 
AutoItWinSetTitle($g_szVersion)
AutoItSetOption("TrayIconHide", 0)
Opt("TrayIconDebug",1)
Opt("WinTitleMatchMode",2)

HotKeySet("!^x", "ExitKill") ;Sets the hot key combination to Ctrl+Alt+X
Dim $on = 1 ;Variable says the program is running
Dim $hour = 0 ;Has MySpace been visited for one hour?
Dim $time = 0
Dim $dif
Dim $strTitle = "Untitled"
Dim $strApplication = "Notepad"
Dim $timeAllowed = 120000 ; enter milliseconds (e.g. 30 seconds = 30000 milliseconds)
Dim $timeElapsed = 0
Dim $timeStarted
Dim $timeAllowedHours = $timeallowed/3600000
MsgBox(1,"Got here","1")
Do  
    ;;;;;;;;;;;;;;;; get started
    If WinExists($strTitle) And $day = _DateToDayValue ( @Year, @Mon, @MDAY ) And $timeElapsed = 0 Then
        MsgBox(1,"Got here","2")
        $timeStarted = @hour + @min/60
        MsgBox(1,"$timestarted",@HOUR + @MIN/60)
    EndIf
    MsgBox(1,"$day",$day)

    ;;;;;;;;;;;; what to do while time hasn't run out
    If WinExists($strTitle) And $day = _DateToDayValue ( @Year, @Mon, @MDAY ) And $timeElapsed < $timeAllowedHours Then
        MsgBox(1,"Got here","3")
        ;Sleep($timeAllowed - $timeElapsed)
        MsgBox(1,"@hour + @min/60",@hour + @min/60)
        $timeElapsed = (@hour + @min/60) - $timeStarted
        ToolTip("Timestarted" & $timestarted & "  :  " & "Timeelapsed" & $timeElapsed & "  :  " & "TimeAllowedHours" & $timeAllowedHours)
        MsgBox(1,"Timeelapsed",$timeElapsed)
        MsgBox(1,"still sleeping",$timeAllowedHours - $timeElapsed)
;AS SOON AS SCRIPT GETS HERE, NOTEPAD IS CLOSED, EVEN THOUGH THERE IS NO WINCLOSE COMMAND HERE!!!
    EndIf

    ;;;;;;;;;;;;;;; what to do if application is closed (stop timer until app opens again)
    If WinClose($strTitle) And $day = _DateToDayValue (@YEAR,@MON,@MDAY) And $timeElapsed < $timeAllowedHours Then
        MsgBox(1,"Got here","4")
        $timeElapsed = (@hour + @min/60) - $timeStarted
        MsgBox(1,"$timeStarted",$timeStarted)
    EndIf

    ;;;;;;;;;;;;;;; what to do when time runs out
    If WinExists($strTitle) And $day = _DateToDayValue ( @Year, @Mon, @MDAY ) And $timeElapsed > $timeAllowedHours Then
        MsgBox(1,"Got here","5")
        MsgBox(45,"Warning","You have one minute to close " & $strApplication & " before it closes due to overuse",10)
        Sleep(6000)
        ;WinClose($strTitle)
    EndIf

    ;;;;;;;;;;;;;;; check to test if application is running when there is still time left
    If WinExists($strTitle) = 0 And $day = _DateToDayValue ( @Year, @Mon, @MDAY ) And $timeElapsed < $timeAllowedHours Then
        MsgBox(1,"Got here","6")
        MsgBox(1,"Message",$strApplication & " is not yet started")
    EndIf
    
    MsgBox(1,"Got here","7")
    ToolTip("Timestarted" & $timestarted & "  :  " & "Timeelapsed" & $timeElapsed & "  :  " & "TimeAllowedHours" & $timeAllowedHours)
    ;$timeElapsed = (@hour + @min/60) - $timeStarted
    MsgBox(1,"Timeelapsed",$timeElapsed)

Until $on = 0 ;Repeat this process until the program is turned off

ToolTip("")

Func ExitKill() ;When the hot key combination is pressed
    $on = 0 ;Turn the program off
EndFunc

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites



What is "If WinClose()" supposed to do? I do not believe that checks to see if the window is closed. I think a "If Not WinExists()" would be better. Could the WinClose be closing your window?

Share this post


Link to post
Share on other sites

What is "If WinClose()" supposed to do? I do not believe that checks to see if the window is closed. I think a "If Not WinExists()" would be better. Could the WinClose be closing your window?

I inherited that and I believe it tells me if the application has been closed while the script is running. However, I did use If WinExist(blahblah) = 0 elsewhere to see what that would do. Not sure if that helps me though... :D

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

SerialKiller is correct. WinClose() is what is killing your app.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Could the WinClose be closing your window?

Now I get it. (Dense) I was thinking that "If Winclose" was looking to see if the program was closed, not that it had closed. I should be able to post a working solution this weekend.

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

You got it to work anyway, but you could also use "If Not ProcessExist(notepad.exe)"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I got the whole thing to work. Please look at this link in scripts and scraps for the code:

Edited by jefhal

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

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
Sign in to follow this  
Followers 0