Jump to content

Recommended Posts

Posted

Hi, i ask you help.

I'm using AutoIT for personal use, i'm not expert.

I have a program that, when starts, it create:

- Taskbar Icon Title (same title of opened window)

- SysTray Icon

- Open its Window on screen

When I close it using "x" it closes only its Window from screen and close it "Taskbar Icon Title" without close its process, infact it is always memory resident: there is its icon in systray.

To unload program from memory, closing it definitively, I must move mouse on systray, click menu and go on "exit".

For this reason i've thinked to use a script that verify "if exist" or "NOT exist" Window of program

and if there is not window: script kill process immediately.

if processexists("Program.exe") and NOT Winexists("Title") then processclose("Program.exe")

unfortunately script answers me that window always exists, also if program shows only its systray icon ...... I can not use this command.

For this reason I need a command that verify if TaskBar shows "Exact Text Title", but I know only the method (learned on forum few weeks ago used in other my little script)

to REMOVE "TASKBAR TEXT" but i don't know how test the existance of "text" in taskbar to complete this row command:

if processexists("Program.exe") and Not Exists ....TASKBAR-TITLE.... Then processclose("Program.exe")

endif

This script remove "TEXT icon" from TaskBar

Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}"

Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}"

Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);"

Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList)

$oTaskbarList.HrInit()

$oTaskbarList.DeleteTab(WinGetHandle("TEXT"))

How is the command can permit me to determinate in "TaskBarList" if there is the "Text"

that I want ?

Thanks

Posted

It looks like you are just deleting the taskbar item and not exiting the script.

When you click the "x" in your Gui (usually from GuiGetMsg() ) using $GUI_EVENT_CLOSE then you would Exit

While 1

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

Exit

Endif

WEnd

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted

Excuse me for stupid question:

If i want close "Program-1.exe" when it closes it's taskbar text

because it is always resident on memory and i'm running also

Program-2.exe

Program-3.exe

and Window focus for example is on Program-3.exe and i close "Program-3.exe"

$msg = $GUI_EVENT_CLOSE is true

but i have not closed program that i want to check event.

I need that

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then...

runs only for one particular program.exe or its "HANDLE" that i have specified.

Posted

Maybe these magical 2 lines is what u want:

$PROCESS = WinGetProcess("[TITLE:My Window Title]", "")
ProcessClose($PROCESS)

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Posted

Yes, you have reason, the window is not closing, but minimized on Tray, infact if i run this:

if winexists("Window Text") then msgbox(0, "", "Window is not close")

the message are always showed.

Unfortunately i don't know how use the command that you have suggest to me "WinGetState()".

I need that script tell me if in taskbar is present or not present the "title of window".

If it is present: window is not minimized on Tray

If it is NOT present: Window is been minimized on Tray therefore script do: processclose("process.exe")

Can you give solution, i'm not expert

Thanks

Posted

Thanks MKISH but the "Window Title" always exist,

the title in taskbar is hidden and window is minimized on tray area.

i must test if are showed "Window Text" on taskbar.

Posted

There is no way to create a tasklist that contain all "window text icon TAB" and check if in this Tasklist

there is the "Window TEXT-SEARCHED" or it's hidden?

Posted

Unless you are searching for specific window names that you already know, you will have to do something like WinList() in a loop and compare the results each time it loops to see if a window is missing, then check the processes to see if it's still running.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted

thank you kaotkbliss but i have original post because i don't know how use command Winlist() to compare the resul with window names that I already know.

For me this command is the solution but i don't know ho use it

Posted

Maybe something like this?

Local $main_list[3] = ["title1","Title2","Title3"]
$list = WinList()
$flag = 0
For $i = 1 To Ubound($list)-1
 For $i2 = 1 To UBound($main_list)
  $check = StringInStr($list[$i][0],$main_list[$i2])
  If $check <> 0 Then
   $flag = 1
   ExitLoop
  Else
   $handle = $main_list[$i2]
  EndIf
 Next
Next
If $flag = 0 Then
 $proc = WinGetProcess($handle)
 If $proc <> -1 Then
  ProcessClose($proc)
 EndIf 
EndIf

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted (edited)

Thanks "kaotkbliss".."JohnOne" and all forum with your suggestion, i have partial solved creating my script on bottom,

but it has a bug.

If program, when it starts, creates immediately its "systray icon" i can know the handle of program, but if i have a program that creates systray icon only when i press on "x" the handle is always "0000" and my script don't run.

How can i determinate handle from "filename.exe" or from its "$pid" without using "systray_udf.au3" ???

I know The text of window but it is a variable Text and i can't use: WinGetHandle ( "title" [, "text"] )

Is interesting your council "kaotkbliss" on your 1st post with this script

While 1

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

Exit

Endif

WEnd

but don't run.

I start my program.exe ...its Window is activate and pressing its "x" to close program

the script don't exit

How can i use this your script ??

Thanks

************* My SCRIPT with bug *************

#NoTrayIcon

#include <systray_udf.au3>

$Program="Application.exe"

Run($Program)

sleep(100)

$ProgramHandle=(_SysTrayIconHandle(_SysTrayIconIndex($Program)))

$ProgramTitle=WinGetTitle($ProgramHandle)

While processexists($Program)

Local $TaskBar=WinList()

For $x=1 To $TaskBar[0][0]

If $TaskBar[$x][0] <> "" And InvisibleTask($TaskBar[$x][1]) Then

if $TaskBar[$x][0]=$ProgramTitle then

Winclose($ProgramHandle)

exit

endif

EndIf

Next

Sleep(300)

Wend

Func InvisibleTask($handle)

If BitAND(WinGetState($handle), 2) Then

Return 0

Else

Return 1

EndIf

EndFunc

Edited by apollo13
Posted (edited)

Is interesting your council "kaotkbliss" on your 1st post with this script

While 1

$msg = GuiGetMsg()

If $msg = $GUI_EVENT_CLOSE Then

Exit

Endif

WEnd

but don't run.

I start my program.exe ...its Window is activate and pressing its "x" to close program

the script don't exit

How can i use this your script ??

Thanks

That was under the assumption you were creating your own gui/window

I'll think over the situation and see if I can figure a solution.

*edit*

you can use just WinGetHandle ("title") the "text" is optional

and you might be able to use winwaitactive("title") instead of sleep(100)

so the beginning could go

$Program="Application.exe"

$title = "program title here"

Run($Program)

WinWaitActive($title)

$ProgramHandle=WinGetHandle($title)

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Posted

Thanks kaotkbliss, but as i wrote in previously post the "program title" change.

The text of window is variable i can't use: WinGetHandle ( "title" )

The program that i use is "Magic Mail Monitor" and when i start it the title is:

"Mail point access - Magic Mail Monitor"

Mail point access is different if i choose different username to control if i not include all point in one istance window.

is not possible know $handle from $pid ??

Posted

I have different mail to check in separate task (not same window of program) with name:

"Google Mail" …

"Telekom Mail"…

"Wind Mail"

and the title of Window changes to

"Google Mail - Magic Mail Monitor" or

"Telekom - Magic Mail Monitor".... or

"Wind Mail - Magic Mail Monitor".

I click on task and program starts with that suffix name.

How i automatically can get handle from script if "title" change for each choice of WEB Mail that i want to check ??

Posted

Thank you very much for suggestion, I will read guide to learn how use the command that you have wrote: I don't know it.

Thank you again, you are very gentile to give me help.

Best regards

Posted

I have solved in this mode: thanks to all

#NoTrayIcon

$Program=("MyProgram.exe")

$PID=Run($Program)

$Handle=WinGetHandleFromPID($PID)

$Title=WinGetTitle($Handle)

While ProcessExists($PID)

if WinGetState($Title)=5 or WinGetState($Title)=37 then Winclose($Handle)

sleep (20)

wend

Func WinGetHandleFromPID($PID)

$hWnd = 0

$stPID = DllStructCreate("int")

Do

$winlist2 = WinList()

For $i = 1 To $winlist2[0][0]

If $winlist2[$i][0] <> "" Then

DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))

If DllStructGetData($stPID, 1) = $PID Then

$hWnd = $winlist2[$i][1]

ExitLoop

EndIf

EndIf

Next

Sleep(100)

Until $hWnd <> 0

Return $hWnd

EndFunc

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