Jump to content

Script to close an application


Recommended Posts

This solution works, but there's other problem we are facing now. Our application (it's processes are closed using similar script as in the link) 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. Application is one of the ERP solution. Any suggestions?

 
Link to comment
Share on other sites

I tried this (it shows all opened windows containing expression1/exp2/exp3):

#include <Array.au3>

Local $var = WinList("[REGEXPTITLE:(?i)(.*exp1.*|.*exp2.*|.*exp3.*)]")
For $i = 1 To $var[0][0]
   If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
        MsgBox(0, "Open windows containing exp1/exp2/exp3", "Title=" & $var[$i][0])
   EndIf
Next

Func IsVisible($handle)
   If BitAND(WinGetState($handle), 2) Then
       Return 1
    Else
       Return 0
   EndIf
EndFunc

Now, where shoud I put a loop through the returned array and run WinClose on each one?

Link to comment
Share on other sites

I think at the moment this script reacts when user is inactive (idle) for some time (n seconds) regardless the app, e. g. if I have ERP app opened, and I go to other application, after n seconds ERP app won't close, if I act like I'm idle, it will close. Any idea?

Link to comment
Share on other sites

  • 7 months later...

No one answered,  so, the script reacts when user is inactive (idle) for some time (n seconds) regardless the app, e. g. if I have ERP app opened, and I go to other application, after n seconds ERP app won't close, if I act like I'm idle, it will close. Any idea?

Link to comment
Share on other sites

I've tried another option:

#include <Timers.au3>
#include <Array.au3>
#RequireAdmin

$count = 0
While 1
Local $var = WinList("[REGEXPTITLE:(?i)(.*X.*|.*Y.*|.*Z.*)]")
_ArrayDisplay($var)

For $i = 1 To $var[0][0]
$state = WinGetState($var[i][0])
$count += 1
       If $var[$i][0] = "" or $state = 0 Then $count = 0
      If $count > 10 Then WinClose($var[i][0])

ToolTip("count = " & $count, 0, 0, "state = " & $state)
Next
Sleep(1000)
WEnd

 

Edited by itauto3
Wrong copy/paste
Link to comment
Share on other sites

Now I get a tooltip, but the window doesn't close after count gets to 5 - everytime I get this error:

Unknown function name.:
If $count > 5 Then WinClose($aWindows

If $count > 5 Then WinClose($aWindows[^ ERROR

>Exit code: 1    Time: 10.48

 

Edited by itauto3
Fault
Link to comment
Share on other sites

Strange, what version of AutoIt do you have?

Also what is your current code as in the error i see

If $count > 5 Then WinClose($aWindows

And in your example code i see:

If $count > 10 Then WinClose($var[0])

Which is different and i am guessing you have changed more things...

Link to comment
Share on other sites

  • Moderators

itauto3,

The error tells you what is wrong and where:

If $count > 10 Then WinClose($var[i][0])

You are missing the leading $ from the $i variable - so AutoIt thinks you are using a first class function, which of course does not exist!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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