great77 Posted April 19, 2016 Share Posted April 19, 2016 Thanks everyone using their time on this forum. Thanks to Melba23 for modifying his suggested script in these 2 programs. I posted this code to appreciate everything have learnt so far in this forum, Much appreciated. In my case, I tested these two scripts and they are working perfectly, but the one where $sText listed to compare with tooltip is preferred First Example ;;; This script listed the hidden tooltip and button number of hidden icon in the system tray and will allow the program to quickly see through the list without missing the tooltip. expandcollapse popupLocal $MyFile ="C:\Program Files (x86)\AAD_Not_Connected\not connected.txt" Local $folder_not_connected = "C:\Program Files (x86)\AAD_Not_Connected\not connected_folder.txt" Global $hSysTray_Handle, $iSystray_ButtonNumber Local $not_connected, $reg, $PID Global $hSysTray_Handle Global $vIsHidden If ProcessExists("explorer.exe") Then ; Will return the PID or 0 if the process isn't found. ProcessClose("explorer.exe") EndIf $reg = 0 ;;; zer0 is ok but if large number for hexadecimal it should be converted see example below but commented out RegWrite("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", $reg) ;;;; RegWrite("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", "0x" & Hex(int($reg))) decimal can be converted to hexadecimal sleep(2000) $vIsHidden = RegRead("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray") sleep(10000) If $vIsHidden == 1 Then Run("rundll32.exe shell32.dll Options_RunDLL 5") WinWait("Notification Area Icons", "") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]") sleep(1000) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]") sleep(500) EndIf $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then ;;;; MsgBox(0, "Error", "Couldn't get the Tray handle") Exit EndIf Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ;get button count If $iSystray_ButCount = 0 Then MsgBox(0, "Error", "No tray icons") Exit EndIf ;;; This will list all the system tray in the console and then identify to look for tooltip better than tooltip scripts ;;; give permission to easily delete folder with files with script $hSysTray_Handle = Get_Systray_Handle() ; Get systray item count $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then MsgBox(16, "", "No items found in system tray") Exit EndIf ; Read tooltip text and parameter For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber) $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) ConsoleWrite($iSystray_ButtonNumber & ": " & $iParam & " - " & $sText & @CRLF) If StringInStr( $sText, "Not Connected, Files") Then ;;; this will help to searcg for substring DirCreate("C:\Program Files (x86)\AAD_Not_Connected") $not_connected = DirCreate("C:\Program Files (x86)\AAD_Not_Connected") ;;;MsgBox(16, "AAD found", "System tray found") _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") ;;; no need to show right click sleep(2000) Local $hEventLog, $aData[4] = [3, 1, 2, 3] $hEventLog = _EventLog__Open("", "Application") _EventLog__Report($hEventLog, 4, 0, 17777, "", "Check if AAD is disconnected and triggered Event Log ID", $aData) _EventLog__Close($hEventLog) ;;;;FileCopy("C:\Windows\notepad.exe", $folder_not_connected, 1) sleep(1000) RunWait(@ComSpec & " /c " & ' @echo The AAD is not connected and will not transfer to GE as at : %DATE% - %time% >> "C:\Program Files (x86)\AAD_Not_Connected\not connected.txt" ', @TempDir, @SW_HIDE) sleep(2000) FileWrite($MyFile, "The AAD is not connected and will not transfer to company" & " Details: " & @ComputerName & " as at " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @SEC) ExitLoop ;;; very important Else DirRemove("C:\Program Files (x86)\AAD_Not_Connected", 1) ;;;;;;;;; MsgBox(16, "NOT found AAD", "AAD Not found") EndIf Next If $vIsHidden == 0 Then Run("rundll32.exe shell32.dll Options_RunDLL 5") WinWait("Notification Area Icons", "") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]") sleep(500) EndIf Func Get_Systray_Handle() $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then MsgBox(16, "Error", "System tray not found") DirRemove("C:\Program Files (x86)\AAD_Not_Connected", 1) Exit Else Return $hSysTray_Handle EndIf EndFunc The Second one : expandcollapse popup;;;; The second one is working, but might not find icon inactive for long time in the system tray, however. It can still find the hidden icon, but some icons are sometimes made redundant by wiindows and might not be able find it by the program Local $MyFile ="C:\Program Files (x86)\AAD_Not_Connected\not connected.txt" Local $folder_not_connected = "C:\Program Files (x86)\AAD_Not_Connected\not connected_folder.txt" Global $hSysTray_Handle, $iSystray_ButtonNumber Local $not_connected, $reg, $PID Global $hSysTray_Handle Global $vIsHidden If ProcessExists("explorer.exe") Then ; Will return the PID or 0 if the process isn't found. ProcessClose("explorer.exe") EndIf $reg = 0 ;;; zer0 is ok but if large number for hexadecimal it should be converted see example below but commented out RegWrite("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", $reg) ;;;; RegWrite("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray", "REG_DWORD", "0x" & Hex(int($reg))) decimal can be converted to hexadecimal sleep(2000) $vIsHidden = RegRead("HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray") sleep(10000) If $vIsHidden == 1 Then Run("rundll32.exe shell32.dll Options_RunDLL 5") WinWait("Notification Area Icons", "") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]") sleep(1000) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]") sleep(500) EndIf $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then ;;;; MsgBox(0, "Error", "Couldn't get the Tray handle") Exit EndIf Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ;get button count If $iSystray_ButCount = 0 Then MsgBox(0, "Error", "No tray icons") Exit EndIf ;;;;MsgBox(0, "Tray icons", $iSystray_ButCount) Global $sToolTipTitle = "Not Connected, Files" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here $not_connected = DirCreate("C:\Program Files (x86)\AAD_Not_Connected") ;;; give permission to easily delete folder with files with script ;;;Global $sToolTipTitle2 = "Not Connected, Files outstanding:" $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle) ;;;$iSystray_ButtonNumber2 = Get_Systray_Index($sToolTipTitle2) If $iSystray_ButtonNumber = 0 Then ;;;;; MsgBox(16, "Error", "Icon not found in system tray") sleep(3000) DirRemove("C:\Program Files (x86)\AAD_Not_Connected", 1) ; 1 means the file not connected.txt will be deleted ;;; Exit Else Sleep(2000) _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") ;;; no need to show right click sleep(2000) Local $hEventLog, $aData[4] = [3, 1, 2, 3] $hEventLog = _EventLog__Open("", "Application") _EventLog__Report($hEventLog, 4, 0, 17777, "", "Check if AAD is disconnected and triggered Event Log ID", $aData) _EventLog__Close($hEventLog) ;;;;FileCopy("C:\Windows\notepad.exe", $folder_not_connected, 1) sleep(1000) RunWait(@ComSpec & " /c " & ' @echo The AAD is not connected and will not transfer to GE as at : %DATE% - %time% >> "C:\Program Files (x86)\AAD_Not_Connected\not connected.txt" ', @TempDir, @SW_HIDE) sleep(2000) FileWrite($MyFile, "The AAD is not connected and will not transfer to " & " Details: " & @ComputerName & " as at " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @SEC) EndIf sleep(3000) ;;If $iSystray_ButtonNumber2 = 0 Then ;; MsgBox(16, "Error", "Icon not found in system tray") ;; Exit ;;Else ;Sleep(2000) ;;_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber2, "right") ;;EndIf ;............ 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) = 1 Then ExitLoop Next If $iSystray_ButtonNumber = $iSystray_ButCount Then Return 0 ; Not found Else Return $iSystray_ButtonNumber ; Found EndIf EndFunc If $vIsHidden == 0 Then Run("rundll32.exe shell32.dll Options_RunDLL 5") WinWait("Notification Area Icons", "") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]") sleep(500) ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]") sleep(500) EndIf 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