Sign in to follow this  
Followers 0
Franco62

Right-click on systray then choose an option

3 posts in this topic

#1 ·  Posted (edited)

Hi everyone.

 

First, sorry for my poor English. I'm not English, I'm French. xD

 

 

I searched a solution to do a right-click on systray icon. On my antivirus (Kaspersky Internet Security) precisely.

 

=> The right click works without any problem, by using this topic : 

 

Then, I searched a solution to choose an option from contextual menu.

I found, with Send command.

 

A windows opens : the configuration of my antivirus.

And so, this window causes me a problem.

 

I must click (left) on "Avancé", like that :

avancy10.jpg

Then I must scroll bar in top, by using the mouse wheel : with command Send ?

And I must click (left) on "Autodéfense", like that :

autody10.jpg

 

I don't reach to do this.

 

This is my script :

 

#include <GuiToolBar.au3>
 
Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
$iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
 
For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
$sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
$iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
If StringInStr($sText, "kaspersky") Then $sKis=$iSystray_ButtonNumber
Next
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $sKis, "right")
Sleep(500)
Send("{UP}{UP}{UP}{ENTER}")
Sleep(500)
 
Local $aList = WinList()
For $i = 1 To $aList[0][0]
If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
if StringInStr($aList[$i][0],"kaspersky") then $hKIS= $aList[$i][1]
EndIf
Next
sleep(500)
WinActive (HWnd($hKIS))
sleep(1500)
Send("{DOWN}{DOWN}")
 

 

This is the party who doesn't work :

 

Local $aList = WinList()
For $i = 1 To $aList[0][0]
If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
if StringInStr($aList[$i][0],"kaspersky") then $hKIS= $aList[$i][1]
EndIf
Next
sleep(500)
WinActive (HWnd($hKIS))
sleep(1500)
Send("{DOWN}{DOWN}")
 

I don't reach :

-> to click on "avancé"

-> to scroll bar on the top with mouse wheel

-> to click on "autodéfense".

 

 

Can you help me, please.

Thank in advance.

 

Best regards,

Thomas.

Edited by Franco62

Share this post


Link to post
Share on other sites



Hi and thank for your help.

 

But I've searched, and I think I found.

 

I've coded this :

#include <GuiToolBar.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <_FileListToArrayNT.au3>

$KISMtmp = @TempDir & "\KISManager\"


if FileExists($KISMtmp) Then DirRemove($KISMtmp,1)
DirCreate($KISMtmp)
Fileinstall("info.jpg",$KISMtmp & "info.jpg")
Fileinstall("KISLogo.jpg",$KISMtmp & "KISLogo.jpg")

Global $Form1 = GUICreate("Form1", 490, 550, 192, 124)
GUISetBkColor(0xFFFFFF)

GUICtrlCreatePic($KISMtmp & "KISLogo.jpg",420,20,40,40)
; présence AV
GUICtrlCreateGroup("Présence de Kaspersky Internet Security", 10, 80, 380, 60, $WS_BORDER)
$LaunchAV = GUICtrlCreateButton("Lancer KIS", 20, 100, 150, 30)
$QuitAV = GUICtrlCreateButton("Fermer KIS", 230, 100, 150, 30)
GUICtrlCreatePic($KISMtmp & "info.jpg",420,90,40,40)
GUICtrlSetTip(-1, "Vous permet soit de lancer ou de fermer Kasperksy Internet Security."&@crlf&"Quelque soit l'action effectuée, n'oubliez pas d'appuyer sur 'actualiser' ensuite.")

; protection AV
GUICtrlCreateGroup("Potection en temps réel", 10, 160, 380, 60, $WS_BORDER)
$ActivateProtect = GUICtrlCreateButton("Activer la protection", 20, 180, 150, 30)
$DeactivateProtect = GUICtrlCreateButton("Désactiver la protection", 230, 180, 150, 30)
GUICtrlCreatePic($KISMtmp & "info.jpg",420,170,40,40)
GUICtrlSetTip(-1, "Vous permet soit de désactiver ou d'activer la protection en temps réel de KIS."&@crlf&"Quelque soit l'action effectuée, n'oubliez pas d'appuyer sur 'actualiser' ensuite.")

; Autodéfense
GUICtrlCreateGroup("Autodéfense", 10, 240, 380, 60, $WS_BORDER)
$ActivateADef = GUICtrlCreateButton("Activer Autodéfense", 20, 260, 150, 30)
$StateAdef = GUICtrlCreateButton("Etat", 180, 265, 40, 20)
$DeactivateAdef = GUICtrlCreateButton("Désactiver Autodéfense", 230, 260, 150, 30)
GUICtrlCreatePic($KISMtmp & "info.jpg",420,250,40,40)
GUICtrlSetTip(-1, "Vous permet d'activer ou de désactiver l'Autodéfense de KIS."&@crlf&@crlf&"Si les deux boutons sont grisés, cela signie que KIS n'est pas ouvert."&@crlf&"Lancez-le an appuyant sur le bouton prévu à cette effet."&@crlf&@crlf&"Ensuite, quelque soit l'action effectuée, n'oubliez pas d'appuyer sur 'actualiser' ensuite.")

; Licence
GUICtrlCreateGroup("Licence", 10, 320, 380, 60, $WS_BORDER)
$ResetTrial = GUICtrlCreateButton("Réinitialiser l'activation", 20, 340, 150, 30)
GUICtrlSetTip(-1, "Pour pouvoir réinitialiser l'activation, il faut impérativement remplir ces deux conditions :" & @CRLF & @CRLF & "1. L'Autodéfense de KIS doit être désactivée." & @CRLF & "2. KIS doit être ensuite fermé.")
$VerifLicence = GUICtrlCreateButton("Vérifier la licence", 230, 340, 150, 30)
GUICtrlCreatePic($KISMtmp & "info.jpg",420,330,40,40)
guictrlsettip(-1,"Vous permet enfin de réinitialiser l'activation."&@crlf&"Or, il se peut que le bouton 'Réinitialiser l'activation'  soit grisé : cela signifie que vous n'avez pas fermer KIS."&@crlf&"Il faut donc le fermer, via le bouton prévu à cet effet. Mais vérifier au préalable que l'Autodéfense soit bien désactivé, sur le bouton prévu à cette effet."&@crlf&@crlf&"Si c'est le bouton 'Vérifier la license' qui vous intéresse mais qui est désactivé, cela signifie que KIS a été fermé."&@crlf&"Il faudra par conséquent appuyez sur le bouton prévu à cette effet pour lancer KIS."&@crlf&@crlf&"Rappel : A chaque action effectuée, n'oubliez pas d'appuyer sur le bouton 'Actualiser'")

; Autres actions
GUICtrlCreateGroup("Autres actions", 10, 420, 380, 60, $WS_BORDER)
$RazAll = GUICtrlCreateButton("Actualiser", 20, 440, 150, 30)
$CloseProg = GUICtrlCreateButton("Quitter le programme", 230, 440, 150, 30)

GUICtrlCreateLabel("Rappel important :",10,500,150,20)
GUICtrlSetColor(-1,0xFF0000)
GUICtrlSetFont(-1,9,550,0,"comic sans ms")
GUICtrlCreateLabel("A chaque action effectuée, n'oubliez pas d'appuyer sur le bouton 'actualiser' !",10,520,600,20)
GUICtrlSetFont(-1,9,550,0,"comic sans ms")





_PresenceKIS()
_StateProtectionKIS()
_StateAutodefKIS()
_StateLicenceKIS()


GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE,$CloseProg
            DirRemove($KISMtmp,1)
            Exit

        Case $RazAll
            _PresenceKIS()
            _StateProtectionKIS()
            _StateAutodefKIS()
            _StateLicenceKIS()

        Case $LaunchAV
            If @OSArch = "X86" Then
                $KISDIR = @ProgramFilesDir & "\Kaspersky Lab"
            Else
                $KISDIR = @ProgramFilesDir & " (x86)\Kaspersky Lab"
            EndIf

            $ResultArray = _FileListToArrayNT($KISDIR, "*", 2, 2)
            For $i = 1 To UBound($ResultArray) - 1
                If Not @error Then
                    If StringInStr($ResultArray[$i], "kaspersky internet security") Then $AVPUI = $ResultArray[$i] & "\avpui.exe"
                EndIf
            Next
            ShellExecute($AVPUI)

        Case $QuitAV

            Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
            $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

            For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
                $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
                $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
                If StringInStr($sText, "kaspersky") Then $sKis = $iSystray_ButtonNumber
            Next
            _GUICtrlToolbar_ClickButton($hSysTray_Handle, $sKis, "right")
            Sleep(500)
            Send("{UP}{enter}")


        Case $ActivateProtect
            Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
            $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

            For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
                $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
                $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
                If StringInStr($sText, "désactivée") Then $sKis = $iSystray_ButtonNumber
            Next

            _GUICtrlToolbar_ClickButton($hSysTray_Handle, $sKis, "right")
            Sleep(500)
            Send("{UP}{UP}{UP}{UP}{UP}{enter}")


        Case $DeactivateProtect
            Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
            $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

            For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
                $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
                $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
                If StringInStr($sText, "kaspersky") Then $sKis = $iSystray_ButtonNumber
            Next

            _GUICtrlToolbar_ClickButton($hSysTray_Handle, $sKis, "right")
            Sleep(500)
            Send("{UP}{UP}{UP}{UP}{UP}{enter}")
            Sleep(500)

            Local $fenetre = WinList()
            For $i = 1 To $fenetre[0][0]
                If StringInStr($fenetre[$i][0], "suspension") Then $ProtecTitle = $fenetre[$i][0]
            Next

            WinMove($ProtecTitle, "", 0, 0)
            WinActive($ProtecTitle, "")
            MouseClick("left", 40, 110, 1)
            Sleep(500)
            MouseClick("left", 40, 140, 1)
            Sleep(500)
            MouseClick("left", 40, 170, 1)
            Sleep(500)
            MouseClick("left", 205, 225, 1)





    EndSwitch
WEnd



Func _PresenceKIS()
    $sKis = 1
    Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
        $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
        If StringInStr($sText, "kaspersky") Then
            $sKis = $iSystray_ButtonNumber
            $SystrayKIS = $sText
        EndIf
    Next

    If $sKis = 1 Then
        GUICtrlSetState($LaunchAV, $gui_enable)
        GUICtrlSetState($QuitAV, $gui_disable)
    Else
        GUICtrlSetState($LaunchAV, $gui_disable)
        GUICtrlSetState($QuitAV, $gui_enable)
    EndIf
EndFunc   ;==>_PresenceKIS

Func _StateProtectionKIS()
    $TitleKIS = 1

    Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
        $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
        If StringInStr($sText, "kaspersky") Then $TitleKIS = $sText
    Next

    If $TitleKIS = 1 Then
        GUICtrlSetState($ActivateProtect, $gui_disable)
        GUICtrlSetState($DeactivateProtect, $gui_disable)
    Else
        If StringInStr($TitleKIS, "désactivé") Then
            GUICtrlSetState($ActivateProtect, $gui_enable)
            GUICtrlSetState($DeactivateProtect, $gui_disable)
        Else
            GUICtrlSetState($ActivateProtect, $gui_disable)
            GUICtrlSetState($DeactivateProtect, $gui_enable)
        EndIf
    EndIf


;~  MsgBox(0, "", $TitleKIS)

EndFunc   ;==>_StateProtectionKIS


Func _StateAutodefKIS()
    $TitleKIS = 1

    Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
        $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
        If StringInStr($sText, "kaspersky") Then $TitleKIS = $sText
    Next

    If $TitleKIS = 1 Then
        GUICtrlSetState($ActivateADef, $gui_disable)
        GUICtrlSetState($DeactivateAdef, $gui_disable)
        GUICtrlSetState($StateAdef, $gui_disable)
    Else
        GUICtrlSetState($ActivateADef, $gui_enable)
        GUICtrlSetState($DeactivateAdef, $gui_enable)
        GUICtrlSetState($StateAdef, $gui_enable)
    EndIf
EndFunc   ;==>_StateAutodefKIS


Func _StateLicenceKIS()
    $sKis = 1
    Global $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)

    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
        $iParam = _GUICtrlToolbar_GetButtonParam($hSysTray_Handle, $iSystray_ButtonNumber)
        If StringInStr($sText, "kaspersky") Then
            $sKis = $iSystray_ButtonNumber
            $SystrayKIS = $sText
        EndIf
    Next

    If $sKis = 1 Then
        GUICtrlSetState($VerifLicence, $gui_disable)
        GUICtrlSetState($ResetTrial, $gui_enable)
    Else
        GUICtrlSetState($VerifLicence, $gui_enable)
        GUICtrlSetState($ResetTrial, $gui_disable)
    EndIf



EndFunc   ;==>_StateLicenceKIS

So, i use winmove to position the window in left boto (x:0 and y:0)

Then I use mouseclick : easy thanks to winmove.

 

And your answer will help me later, I'm sure.

 

Thank.

Best regards,

Thomas.

Share this post


Link to post
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
Sign in to follow this  
Followers 0