Jump to content

Script to close an app


 Share

Recommended Posts

Here is the code I am working with

#include <Timers.au3>

;Declare the Timer:
Global $TIMER = TimerInit()


While 1

;If this application is active then reset the timer:
If WinActive("iexplorer.exe") Then
$TIMER = TimerInit()
EndIf

;if the timer is more than 15 minutes then:
If TimerDiff($TIMER) >= 1 * 60 * 1000 Then
MsgBox (0, "Time reached", "You have been idle for more than 1 minutes.")
ProcessClose("iexplorer.exe")
Exit
EndIf



;Sleep for 1 seconds before looping again:
Sleep(1000)
WEnd

I got this script from and modified it slightly

My goal is to have this script (turned into an exe) constinatly running and looking for the app iexplorer.exe and when it is open, have this AutoIT script close it after it being idle for so many minutes. I have tried the If _Timer_GetIdleTime() variable with no luck.

Any help would be greatly appreciated

Thanks

Grimm

Thanks

Grimm

Link to comment
Share on other sites

are you shure that win title is "iexplorer.exe"?

maybe you need ProcessExists command or WinClose WinKill instead ProcessClose if your using title?

#include <Timers.au3>
While 1
If _Timer_GetIdleTime() >= 1 * 60 * 1000 Then
     MsgBox (0, "Time reached", "You have been idle for more than 1 minutes.", 5); the trick is to set timer on msgbox to close it self after some time :P, or use some command that dont pause script
     ProcessClose("iexplorer.exe")
     Exit
EndIf
WEnd
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Thanks bogQ for the quick reponse.

No I am sure if the actual title is iexplorer.exe. I just used that as an example.

Quick question, I like to the script you posted, however how does the script, that you just posted, know when that app (iexplorer.exe) is open?

Thanks

Grimm

Thanks

Grimm

Link to comment
Share on other sites

it doesnt, it checks only if user is idel for some time and try to kill process

if you need to check if proces exsist then use ProcessExists() command

eather way i whud check if win exsist cos its safer, so IE have IEFrame win class

so If WinExists('[CLASS:IEFrame]') Then WinClose('[CLASS:IEFrame]')

edit: or

If WinExists('[CLASS:IEFrame]') And WinActive('[CLASS:IEFrame]') Then WinClose('[ACTIVE]')

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • Moderators

Hi, grimmlock. Have you tried the suggestions you're receiving? Both WinExists/WinClose and ProcessExists/ProcessClose will work whether the window is active or not.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Yea, I am using a combination which works great. Here is the script I am using:

I think I was able to fix the minor bugs for now =)

#include <Timers.au3>

;Declare the Timer:
; Global $TIMER = TimerInit()


While 1

    ;If this application is active then reset the timer:
;WinExists("Polaris Shortcut Bar") And 
    If ProcessExists("polaris.exe") And _Timer_GetIdleTime() >= 5 * 1000 Then 
  MsgBox (0, "Time reached", "You have been idle for more than 5 seconds.")
ProcessClose("polaris.exe")
EndIf

    ;Sleep for 1 seconds before looping again:
;    Sleep(1000)
WEnd

Thanks everyone for the help

Grimm

Thanks

Grimm

Link to comment
Share on other sites

  • 5 years later...

This solution works, but there's other problem we are facing now. Our application (it's processes are closed using similar script as in this thread) doesn't detect this as logout, so user status/session is still seen as 'login' instead of 'logout'. If we click on X in application window, this is regarded as 'logout' as it should be. Any suggestions?

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...