Jump to content
itauto3

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?

 

Share this post


Link to post
Share on other sites

Easy and fast is to send an mouse click to the coordinates of the "X" which are always the same. More elegant solution is to use the IE UDF to logout/close the app.

Share this post


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

Share this post


Link to post
Share on other sites

If I use this:

$var = WinList("[REGEXPTITLE:(?i)(.*Note.*)]")

all Notepad windows are normally closed with posted code. If I enter part of the name of our ERP window(s), no success.

Share this post


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

Share this post


Link to post
Share on other sites

Please, can anyone help me with closing app, that is running in background/behind other windows, that I don't want to close.

Share this post


Link to post
Share on other sites

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

 

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

×
×
  • Create New...