After some more testing and looking through the forum i found the task bar method to find an icon and click that, navigate once up and hit enter which effectively closes Evernote. But when windows is locked it seems that this is not working (would make sense):
#Include <GuiToolBar.au3>
AutoItSetOption("WinTitleMatchMode", 2)
#NoTrayIcon
Global $hSysTray_Handle, $iSystray_ButtonNumber
Global $sToolTipTitle = "Evernote" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here
While True
Sleep(100)
If ProcessExists("logonui.exe") then
$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)
If $iSystray_ButtonNumber = -1 Then
MsgBox(16, "Error", "Icon not found in system tray")
Exit
Else
;Sleep(500)
WinActivate('[Class:Shell_TrayWnd]')
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right", True, 1, 0)
Send("{UP}")
Send("{ENTER}")
MsgBox(0, "Success", "program closed")
EndIf
Exit
EndIf
WEnd
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 =========== "OLD" instruction
For $iSystray_ButtonNumber = 1 To $iSystray_ButCount ; =========== MODIFIED instruction
If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop
Next
;If $iSystray_ButtonNumber = $iSystray_ButCount Then ;=========== "OLD" instruction
If $iSystray_ButtonNumber = $iSystray_ButCount + 1 Then ; =========== MODIFIED instruction
Return 0 ; Not found
Else
Return $iSystray_ButtonNumber ; Found
EndIf
EndFunc
Had to set Evernote to always show its icon for it to work.
Any idea on how to still get this working even though the Computer is then locked?