Some additions to Melba23's code that take into account overflow section of system tray and correct bug with indexing 0th item on the toolbar:
#Include <GuiToolBar.au3>
#include <GuiButton.au3>
Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "Pointing" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
If $iSystray_ButtonNumber = -1 Then
MsgBox(16, "Error", "Icon not found in system tray")
Exit
Else
Sleep(500)
; right click and select first menu item
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
Send("{DOWN}{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
; check overflow section of systray
Return Get_OverflowSystray_Index($sToolTipTitle)
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 Get_OverflowSystray_Index($sToolTipTitle)
Else
Return $iSystray_ButtonNumber ; Found
EndIf
EndFunc
Func Get_OverflowSystray_Index($sToolTipTitle)
$hSysTray_Handle = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]')
$iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
If $iSystray_ButCount = 0 Then
MsgBox(16, "Error", "No items found in system tray")
Exit
EndIf
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
$hSysTray_OverflowButton = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[CLASS:Button; INSTANCE:1]')
_GUICtrlButton_Click($hSysTray_OverflowButton)
Return $iSystray_ButtonNumber ; Found
Else
Return -1
EndIf
EndFunc