JavaAutomater Posted November 19, 2009 Share Posted November 19, 2009 I want to find out which executable ( if possible, with complete path ) is associated with a button/icon in the notification area ( system tray ) Note that I DO NOT have admin rights/debug privileges on the system. Link to comment Share on other sites More sharing options...
Authenticity Posted November 19, 2009 Share Posted November 19, 2009 Try _SysTray UDF by wraithdu. Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 19, 2009 Author Share Posted November 19, 2009 Wow! How did I miss this UDF? I did search a lot but never got this as a hit! Am looking into it, and will come back if I have any doubts :-D Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 19, 2009 Author Share Posted November 19, 2009 (edited) A quick update : I just ran the example script in the post and it deleted ALL the notification area icons! I have 9 icons in the area, all of which are visible and the example script gives me this output: Count visible tray: 9 index: 8 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 7 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 6 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 5 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 4 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 3 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 2 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 1 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 index: 0 visible: -3 handle: -3 pid: -1 proc: title: 0 tooltip: -3 >Exit code: 0 Time: 0.312 This means that _SysTrayIconHandle fails, and I think that _SysTrayGetButtonInfo is failing. Right away, off the top of my head, I think that ReadProcessMemory etc is failing as I don't have Admin privileges/debug rights. Any clues? Edited November 19, 2009 by JavaAutomater Link to comment Share on other sites More sharing options...
Authenticity Posted November 19, 2009 Share Posted November 19, 2009 (edited) Change this in _SysTrayGetButtonInfo: If @OSArch = "X86" Then $taglocalTBBUTTON = "int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[2];dword_ptr dwData;int_ptr iString" Else ; X64 $taglocalTBBUTTON = "int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[6];dword_ptr dwData;int_ptr iString" EndIf to: If @OSArch = "X86" Then $taglocalTBBUTTON = "int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[2];uint_ptr dwData;int_ptr iString" Else ; X64 $taglocalTBBUTTON = "int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[6];uint_ptr dwData;int_ptr iString" EndIf Edited November 19, 2009 by Authenticity Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 19, 2009 Author Share Posted November 19, 2009 VIOLA! It works! It works without ANY admin rights/privileges! Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 19, 2009 Author Share Posted November 19, 2009 (edited) I still have a problem. After locating the icon, I want to right click on it ( to get the menu ) and se;ect an option in that menu. Right now, I cannot get to spawn the menu at all using the following code "that should work": expandcollapse popup#include "_SysTray.au3" #include <Process.au3> AutoItSetOption("MustDeclareVars", 1) Opt("TrayIconDebug", 1) ; shows the current script line in the tray icon tip to help debugging Local $msgBoxTitle = "JA"; Local $count = _SysTrayIconCount() ConsoleWrite("Count visible tray: " & $count & @CRLF) Local $i = 0; For $i = $count - 1 To 0 Step -1 Local $handle = _SysTrayIconHandle( $i ) Local $visible = _SysTrayIconVisible( $i ) Local $pid = WinGetProcess( $handle ) Local $name = _ProcessGetName( $pid ) Local $title = WinGetTitle( $handle ) Local $tooltip = _SysTrayIconTooltip( $i ) If ("AutoIt3.exe" == $name) And ( $title == "AutoIt v3" ) Then ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) ; found the thing we are to close! TrayTip( $msgBoxTitle, "Located program successfully with tooltip '" & $tooltip & "'", 17, 1 ) Sleep( 3500 ) If 0 == ControlClick( "", "", $handle, "menu" ) Then ;If 0 == ControlClick( "", "", $handle, "left", 1 ) Then ;If 0 == WinMenuSelectItem( $handle, "", "" ) Then TrayTip( $msgBoxTitle, "Right click on button Failed!", 17, 2 ) MsgBox(0, $msgBoxTitle, "Right click on button Failed!", 5) Sleep( 500 ) Exit EndIf EndIf ;ConsoleWrite( @OSVersion ); ;ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) Next Sleep( 10000 ) The code sucessfully detects the icon, but cannot supposedly right/left click on it ?! Edited November 19, 2009 by JavaAutomater Link to comment Share on other sites More sharing options...
wraithdu Posted November 19, 2009 Share Posted November 19, 2009 (edited) What version of AutoIt are you using? I guess 'dword_ptr' was introduced in a beta somewhere that you don't have. Good catch Authenticity. Edited November 19, 2009 by wraithdu Link to comment Share on other sites More sharing options...
wraithdu Posted November 19, 2009 Share Posted November 19, 2009 The $handle is not a control handle, it is the window handle of the process that owns the tray icon. It doesn't have anything you can click. You'll have to send a right-click at the coordinates of the icon to invoke the menu. Then maybe you can manipulate the menu to select the option you want...not sure about that part, or send another mouse click. Link to comment Share on other sites More sharing options...
wraithdu Posted November 19, 2009 Share Posted November 19, 2009 (edited) You can also try this function to click the tray item, but I can't find the original topic where it came from. expandcollapse popup;=========# _SysTray_ClickItem #====================================================== ; ;Function Name: _SysTray_ClickItem() ;Description: Click on item in Windows system tray by any substring in the title ;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item). ; $iButton - [optional] The button to click, "left" or "right". Default is the left button. ; $iClick - [optional] The number of times to click the mouse. Default is 1 ; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved ; $iSpeed = [optional] Mouse movement speed ;Return Value(s): Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 if required item not found ;Requirement(s): AutoIt 3.2.10.0 and above ;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea) ; ;==================================================================================== Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1) Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(1, 0, 0) EndIf $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $iButCount = 0 Then Return SetError(1, 0, 0) EndIf $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button1") If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button1") For $i = 0 To $iButCount - 1 $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then _GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed) Return 1 EndIf Next Return SetError(1, 0, 0) EndFunc Edited November 19, 2009 by wraithdu Link to comment Share on other sites More sharing options...
wraithdu Posted November 19, 2009 Share Posted November 19, 2009 Ah, finally found it: http://www.autoitscript.com/forum/index.php?showtopic=63397 Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 20, 2009 Author Share Posted November 20, 2009 This does not seem to work - script should bring up the AutoIt button menu, but does not. Instead, it clicks on start button ( this happens VERY fast and you will not notice it unless you record the screen and play it back in slow motion ) Here is the test script: expandcollapse popup#include "_SysTray.au3" #include <Process.au3> AutoItSetOption("MustDeclareVars", 1) ;Opt("TrayIconDebug", 1) ; shows the current script line in the tray icon tip to help debugging. We CANNOT use this in this script as we need the tooltip to stay constant Local $msgBoxTitle = "JA"; Local $count = _SysTrayIconCount() ConsoleWrite("Count visible tray: " & $count & @CRLF) Local $i = 0; For $i = $count - 1 To 0 Step -1 Local $handle = _SysTrayIconHandle( $i ) Local $visible = _SysTrayIconVisible( $i ) Local $pid = WinGetProcess( $handle ) Local $name = _ProcessGetName( $pid ) Local $title = WinGetTitle( $handle ) Local $tooltip = _SysTrayIconTooltip( $i ) If ("AutoIt3.exe" == $name) And ( "AutoIt v3" == $title ) Then ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) ; found the thing we are to close! TrayTip( $msgBoxTitle, "Located program successfully with tooltip '" & $tooltip & "'", 17, 1 ) Sleep( 10000 ) ;If 1 <> _SysTray_ClickItem_( $tooltip, "left", 2 ) Then If 1 <> _SysTray_ClickItem_( $tooltip, "left", 1 ) Then ; Should bring up the button menu, but does not. Instead, it clicks on start button ( this happens VERY fast and you will not notice it unless you record the screen and play it back in slow motion ) TrayTip( $msgBoxTitle, "Left click on button Failed!", 17, 2 ) MsgBox(0, $msgBoxTitle, "Left click on button Failed!" ) Exit Else TrayTip( $msgBoxTitle, "Left click on button succeeded!", 17, 2 ) MsgBox(0, $msgBoxTitle, "Left click on button succeeded!" ) EndIf EndIf ;ConsoleWrite( @OSVersion ); ;ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) Next Sleep( 10000 ) #include <GuiToolBar.au3> ;http://www.autoitscript.com/forum/index.php?showtopic=63397 ;=========# _SysTray_ClickItem #====================================================== ; ;Function Name: _SysTray_ClickItem() ;Description: Click on item in Windows system tray by any substring in the title ;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item). ; $iButton - [optional] The button to click, "left" or "right". Default is the left button. ; $iClick - [optional] The number of times to click the mouse. Default is 1 ; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved ; $iSpeed = [optional] Mouse movement speed ;Return Value(s): Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 if required item not found ;Requirement(s): AutoIt 3.2.10.0 and above ;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea) ; ;==================================================================================== Func _SysTray_ClickItem_($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1) Local $i Local $hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(1, 0, 0) EndIf Local $iButCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $iButCount = 0 Then Return SetError(1, 0, 0) EndIf ; FIXME : Why are we doing this? Local $hButton = ControlGetHandle( "[Class:Shell_TrayWnd]", "", "Button1" ) If $hButton <> "" Then ControlClick( "[Class:Shell_TrayWnd]", "", "Button1" ) Local $ToolTips = ""; For $i = 0 To $iButCount - 1 Local $cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i) ;$ToolTips &= _GUICtrlToolbar_GetButtonText($hToolBar, $cID) & @LF; $ToolTips &= _GUICtrlToolbar_GetButtonText($hToolBar, $cID) & "|"; If 0 <> StringInStr( _GUICtrlToolbar_GetButtonText( $hToolBar, $cID ), $iTitle ) Then _GUICtrlToolbar_ClickButton( $hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed ) ConsoleWrite( "Was looking for ( and found ) '" & $iTitle & "' in list : " & $ToolTips & @CRLF ) Return 1 EndIf Next ConsoleWrite( "Was looking for ( but not got ) '" & $iTitle & "' in list : " & $ToolTips & @CRLF ) MsgBox(0, $iTitle, $ToolTips ); Return SetError(1, 0, 0) EndFunc Link to comment Share on other sites More sharing options...
JavaAutomater Posted November 25, 2009 Author Share Posted November 25, 2009 Bump Link to comment Share on other sites More sharing options...
JavaAutomater Posted December 14, 2009 Author Share Posted December 14, 2009 bump Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now