Jump to content
Sign in to follow this  
Slarti

Can AutoIt get at one item in the SysTray

Recommended Posts

Slarti

First posting here, so be gentle with me :graduated:

On Windows XP (at this point in time) I am trying to set up an AutoIt GUI or script to react to the closing of a program by passing 2 mouse clicks to an item in the System Tray.

My problems are that the System Tray does not have a title, nor does the item in it, though both have a Class

The tray's class is Shell_TrayWnd

The item (program) is #32768

Does the fact that I know the name of the underlying program help at all?

Cheers

Slarti

Share this post


Link to post
Share on other sites
Melba23

Slarti,

Welcome to the AutoIt forum. :graduated:

This thread shows how to interact with icons in the Systray. Come back if you have any trouble integrating it with your script. ;)

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
Slarti

Hi M23,

Thanks for the link.

This is my first time back on the site that has the need for this functionality and I am having a few oddities trying to run this.

As you can see below I have only tweaked your code a very little to try and achieve the Logout that is needed and what is driving me crazy is that sometimes it works perfectly, sometimes it does not return a $iSystray_ButtonNumber and sometimes it causes a right click on the Taskbar, so that I see the menu that includes Task Manager, Lock the Task Bar etc.

The icon that I am trying to click onhas been in the same position all through the session and no other icons have been added or removed, so to put it mildly, I am confused.

Oh, I am running everything from a 3 line batch file, on the desktop which is

T:

T:\SUN32.EXE N:\MDF\Standard.mdf

"C:\Program Files\AutoIt3\autoit3.exe" C:\Sun\Autoit\SunLogOut.au3

Would moving lines 1 and 2 into the script and compiling everything help? Or am I missing something blindingly obvious. As usual :graduated:

#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

ProcessWaitClose("SUN32.EXE")

Sleep(300)

Global $sToolTipTitle = "SunSystems - logged in as SDT" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

Sleep(100)

If $iSystray_ButtonNumber = 0 Then

MsgBox(16, "Error", "Icon not found in system tray")

Exit

Else

Sleep(500)

_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")

Sleep(100)

Send("{UP}")

Sleep(100)

Send("{ENTER}")

EndIf

Exit

;............

Func Get_Systray_Index($sToolTipTitle)

; Find systray handle

$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')

If @error Then

MsgBox(16, "Error", "System tray not found")

Exit

EndIf

; Get systray item count

Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

If $iSystray_ButCount = 0 Then

MsgBox(16, "Error", "No items found in system tray")

Exit

EndIf

; Look for wanted tooltip

For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1

If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop

Next

If $iSystray_ButtonNumber = $iSystray_ButCount Then

Return 0 ; Not found

Else

Return $iSystray_ButtonNumber ; Found

EndIf

EndFunc

Share this post


Link to post
Share on other sites
Melba23

Slarti,

Why do you have the ProcessWaitClose("SUN32.EXE") line? That will pause the script until the SUN32.EXE process no longer exists - do you think it likely that the tray icon will be present to click at that point? :graduated:

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
Slarti

Hi M23

SUN32.EXE and the Tray icon are associated, but not the same.

The tray icon is is provided by the program SULoginMonitor.exe with the intention of keeping the user logged into the Sun32.exe environment even though the program has been closed. To fully log out a right click on the icon is needed, followed by selecting Log Out [userID]

The reasons I am trying to get this to be automated on the shutdown of Sun32.exe are

1) so that I can run automated routines that will go into Sun32, do things and then log out cleanly

2) so that people do have to log into Sun32 each time they want to use it, so as to re-instate the security feature of a login that the program authors have suddenly decided is no longer a good idea.

I can get round the logout by totally disabling the SULoginMonitor.exe with a registry hack, but this has 2 downsides

1) the login screen pops up twice, which is a PITA

2) the program authors know I am doing this and are almost certain to try and prevent it in a future release

Anyway, what I am after is to trigger the right click on the tray icon by the closure of a different, but associated program

Cheers

Slarti

Share this post


Link to post
Share on other sites
Melba23

Slarti,

I understand now. I have tested your script on several unrelated processes and it works for me every time. :graduated:

A couple of thoughts:

- 1. Is the SULoginMonitor.exe icon visible permanently or might it be hidden?

- 2. Are you sure that the icon tooltip text is exactly as you have it? Better to have too little (which will match) than too much (which might not).

- 3. Try increasing the Sleep(300) to give the systray a chance to calm down and rearrange the icons once the main process has ended - although I think that is really clutching at straws. :)

Other than that I am stumped. ;)

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
Slarti

Hi M23

- 1. Yes, all the time. It is loaded by a registry entry and stays there until the system is shut down.

- 2. I will double check that, though I think that all that could be there in addition to what I have is some trailing spaces

- 3. I like the idea of Systray having to calm down. Puts a smile on my face, even if it is not the solution.

I'll give this some testing, when I get the chance, but other customers and a weeks holiday (Woo Hoo!) probably means that I won't get at it until early November.

Thanks for the help so far and I'll report back, when I have something to report.

TTFN

Slarti

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  

×