Jump to content

Check if program is running under system tray


 Share

Recommended Posts

Well... the reason being is that there is two states. Its a Cisco VPN device. In the process list it shows up as vpngui.exe which is fine, however I want to know if its running or not. When it is not running, it shows up as a yellow padlock in the systray thats unlocked. When Its connected it shows up as a green lock.

If you mouseover, the following text is shown respectfully "RSVPN Dialer - Disconnected" or "RSVPN Dialer - Connected"

I was just curious if there was any way at all, to check whether its connected or disconnected :whistle: I hope this explains well enough... if not let me know

Link to comment
Share on other sites

Well... the reason being is that there is two states. Its a Cisco VPN device. In the process list it shows up as vpngui.exe which is fine, however I want to know if its running or not. When it is not running, it shows up as a yellow padlock in the systray thats unlocked. When Its connected it shows up as a green lock.

If you mouseover, the following text is shown respectfully "RSVPN Dialer - Disconnected" or "RSVPN Dialer - Connected"

I was just curious if there was any way at all, to check whether its connected or disconnected :whistle: I hope this explains well enough... if not let me know

Cisco VPN Client has commandline parameters. I bet there is one to get the connection state!

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 1 month later...

hm, i also stumbled about a similar problem: in our office we use cardreaders and cards with our pgp keys on them. in order to encrypt/decrypt mails, we have to put our ID cards into the cardreader. when it's time to go home or go out for lunch we often forget to take back the ID cards - thus we cannot enter the building anymore because we need them to open the door :whistle:

so i thought i'd write a script that activates the systemspeaker with a loud beep - whenever you either lock your workstation and leave the card in the reader or shutdown and leave the card in the reader.

now here's the problem: there is no commandline tool or program to figure out the state of the cardreader - or is there? otherwise i'd have to write a script that reads the color of the icon of "cardreader application" in the systray (yellow for "card in" and grey for "not present").

i hope you can follow me :P same problem as the threadcreator.

thanks in advance

Link to comment
Share on other sites

  • 4 years later...

Hi,

I'd like to do something similar.

I need to known if Ultra VNC's icon is in fact in the system tray.

I know the process (WinVNC.exe) is already running so that lets me know if I need to even check. But how to check if the icon is there or not?

The issue is that it runs itself twice:

"C:\Program Files\UltraVNC\WinVNC.exe" -service

"C:\Program Files\UltraVNC\WinVNC.exe" -service_run

So a way to detect if both are running would work too? At the moment I only know how to check if WinVNC.exe is running. Which of course it already is before it loads the icon.

Thanks,

Will

Edited by war59312
Link to comment
Share on other sites

  • Moderators

war59312,

If the systray icon has a tooltip attached, you can find it using this: ;)

#Include <GuiToolBar.au3>

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

Global $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
Else
    MsgBox(64, "Found", "Icon found in system tray")
EndIf

Exit

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

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    Local $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

I hope it helps. :huh2:

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

 

Link to comment
Share on other sites

Hey,

Indeed it does. Now to only figure out how to run:

C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd" UltraVNC.cmd

When the icon is found.

I tried:

$PID = Run(C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd" & "\UltraVNC.cmd", "", @SW_SHOW)

But get a script error.

Thanks again,

Will

Edited by war59312
Link to comment
Share on other sites

  • Moderators

war59312,

Try this - using single quotes to define the first parameter:

$PID = Run('C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd" \UltraVNC.cmd', "", @SW_SHOW)

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

 

Link to comment
Share on other sites

Hey,

Well, after a bit of learning curve here Is what I am currently using to fit my need of automating my Windows start-up routine. :huh2:

#Include <GuiToolBar.au3>

AutoItSetOption("TrayIconHide", 1)

Global $sToolTipTitle = "WinVNC" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

Global $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

Global $isWinvncRunning = "" ;
Global $isHamachiRunning = "" ;

If $iSystray_ButtonNumber = 0 Then
    
    $isWinvncRunning = "False"
    
    ;MsgBox(16, "Error", "winvnc is not running")
    
    $sToolTipTitle = "Hamachi" ;
    
    $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)  
    
    If $iSystray_ButtonNumber = 0 Then
    
        $isHamachiRunning = "False"
        
        ;MsgBox(16, "Error", "Hamachi is not running")
        
    Else
        
        $isHamachiRunning = "True"
        ;MsgBox(16, "Error", "Hamachi is running")
    
    EndIf
    
Else

    $isWinvncRunning = "True"
    
    ;MsgBox(16, "Error", "winvnc is running")
    
    $sToolTipTitle = "Hamachi" ;
    
    $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)  
    
    If $iSystray_ButtonNumber = 0 Then
    
        $isHamachiRunning = "False"
        ;MsgBox(16, "Error", "Hamachi is not running")
        
    Else
        
        $isHamachiRunning = "True"
        ;MsgBox(16, "Error", "Hamachi is running")
    
    EndIf
    
EndIf   
    
Select
    Case $isHamachiRunning = "True" And  $isWinvncRunning = "True"
        ;MsgBox(0, "", "Both Are True")
        RunWait('C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd\scripts" ProcessExplorerTrueTrue.ahk', "", @SW_HIDE)
    Case $isHamachiRunning = "False" And  $isWinvncRunning = "False"
        ;MsgBox(0, "", "Both Are False")
        RunWait('C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd\scripts" ProcessExplorerFalseFalse.ahk', "", @SW_HIDE)
    Case $isHamachiRunning = "True" And  $isWinvncRunning = "False"
        ;MsgBox(0, "", "Hamachi is Is True And WinVNC Is False")
        RunWait('C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd\scripts" ProcessExplorerTrueFalse.ahk', "", @SW_HIDE)
    Case $isHamachiRunning = "False" And  $isWinvncRunning = "True"
        ;MsgBox(0, "", "Hamachi Is False And WinVNC Is True")
        RunWait('C:\Windows\System32\HIDE.EXE /w c:\windows\syswow64\cmd.exe /c c:\windows\sysnative\cmd.exe /c start /b /w /D"C:\StartAndEnd\scripts" ProcessExplorerFalseTrue.ahk', "", @SW_HIDE)
    Case Else
        MsgBox(0, "", "Bug")
EndSelect
    
Exit

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

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    Local $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

So pretty simple really. It is checking to see if two products are running, Hamachi and WinVNC. Then running the correct AutoHotkey script to do a few things to Process Explorer when I boot up my computer.

I'm also making use of Easy Macro Recorder @ http://www.flashplayerpro.com/MacroRecorder/ to do a few things. So using AutoIt, AutoHotkey, and Easy Macro Recorder. I'm sure AutoIt can probably do everything I need but don't know how, yet.

I left a lot of extra stuff in there for my debugging needs. I'm just glad Windows finally (with Win7) remembers placement of system tray icons.

Thanks for all the help.

Will

Link to comment
Share on other sites

  • 6 years later...
On ‎16‎/‎06‎/‎2011 at 7:15 PM, Melba23 said:

war59312,

 

If the systray icon has a tooltip attached, you can find it using this: ;)

 

#Include <GuiToolBar.au3>

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

Global $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
Else
    MsgBox(64, "Found", "Icon found in system tray")
EndIf

Exit

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

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    Local $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

I hope it helps. :huh2:

 

M23

Hi M23, this doesn't seem to work at all.
It keeps saying Icon not found in system tray, regardless of what I changed the sToolTipTitle to. (I changed it to "Steam" because that's on the system tray and not in the overflow section).

I have to use a right-click-close rather than processClose on this certain program (MSI Dragon Center). 

 

Edited by masCh

-itisallinthemind-

Link to comment
Share on other sites

  • Moderators

masCh,

As I posted that code in 2011, I would have developed it on Win7 - later OSes significantly changed the way they deal with the systray (or notification area as it is now called) so I am not surprised that the code does not work nowadays. If I find time I might look into updating it, but I do not have a lot of spare time at present so do not hold your breath!

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...