Jump to content

Recommended Posts

Posted

Hello everyone!  I am completely new to AutoIT and am wondering how do I make a simple Yes and No Pop up Window that will run a script if the user clicks 'yes,' or just close the window if they click 'no.'  I tried using the GUI wizard to make the message box, which I was successful doing, but I do not know where and how to add in another script that I found elsewhere to make it run if I click 'yes' on the message box.

Posted (edited)

 It's a code I found off the Internet that work for exactly what I needed:

#comments-start

AutoIt Version: 3.0
Language:       English
Platform:       WinXP and above
Author:         Siva Mulpuru (http://www.linkedin.com/in/sivamulpuru)
Script Function:
                Logoff from a sepcific XenApp Server using connection center 
                Tested with Receiver 3.x

#comments-End
#include <GuiTreeView.au3>
;MsgBox(0,"Result", @OSArch)
If @OSARCH = "x86" Then
    $concenter = "C:\Program Files\Citrix\ICA Client\concentr.exe"
Else
    $concenter = "C:\Program Files (x86)\Citrix\ICA Client\concentr.exe"
EndIf

Run($concenter)
WinActivate("Citrix Connection Center")
WinWaitActive("Citrix Connection Center")
;Give Connection Center enough time to populate the session information
Sleep(3000)

$hTreeView = ControlGetHandle("[Title:Citrix Connection Center]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
$hItemRoot = _GUICtrlTreeView_FindItem($hTreeView, 'Active', True, 0 )
$hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItemRoot)

;Check for ICA sessions
if $hFirstChild <> 0 Then
   $SiblingCount = _GUICtrlTreeView_GetSiblingCount($hTreeView, $hFirstChild)
   For $i = 0 To ($SiblingCount - 1) Step +1
      $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $hItemRoot,$i)
      $XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)
      ;MsgBox(0,"Result", $XenAPPSrv)
      ;Look for the required Server
      ;^WKENAH\w+ - WKENAH$$$$$215
      if StringRegExp($XenAPPSrv, "^WKENAH\w+", 0) = 1 Then
         ;MsgBox(0,"Result", "EPICSessionFound")
         ;RightClick on the ServerName
          _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "menu", False, 1)
          ;Send Logoff command
          Send("{Down 4}{Enter}")
          ;Confirm the logoff
          WinActivate("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
          WinWaitActive("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
          Send("&Yes")
          ;Work Done 
          ExitLoop         
      EndIf
   Next   
EndIf
WinClose("Citrix Connection Center", "")
Exit

 

Edited by JLogan3o13
Posted

Please use the code tags (The little <> in the editor) when posting code in the future. I don't exactly see where you want a yes/no message box to go in there?

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Posted

Sorry, will do!

Basically, I'd like to have the yes/no window pop up and then if the user clicks 'yes', it will run the above script (which logs a user off of their Citrix Server). 

Posted
5 hours ago, anthonyjr2 said:
$aBox = MsgBox(4, "Message", "Click yes or no")
If $aBox = 6 Then
    MsgBox(0, "Yes", "Yes was clicked")
ElseIf $aBox = 7 Then
    MsgBox(0, "No", "No was clicked")
EndIf

This is how you do it.

So I was able to use your code above to run the other .exe file that contains the final script I want to run after clicking yes:

Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(8244,"Cerner Log-Off","This will close all Cerner programs.  Continue?")
Select
   Case $iMsgBoxAnswer = 6 ;Yes
Run("C:\Users\Joe\Desktop\SessionLogOff.exe")
   Case $iMsgBoxAnswer = 7 ;No

EndSelect

But the only issue is I have to have the SessionLogOff.exe file on the same computer as my other .exe file.  How do I use your message box window to run the long script I posted earlier after clicking the 'yes' button.  I am such a beginner at AutoIt I have no clue what I am doing!

Posted

bballjoe12,

Try this...see comments...

#comments-start

    AutoIt Version: 3.0
    Language:       English
    Platform:       WinXP and above
    Author:         Siva Mulpuru (http://www.linkedin.com/in/sivamulpuru)
    Script Function:
    Logoff from a sepcific XenApp Server using connection center
    Tested with Receiver 3.x

    #comments-End
    #include <GuiTreeView.au3>

    ; verification

    if MsgBox(4, "Logoff", "Click YES to Logoff") <> 6 then exit msgbox(17,'Logoff Canceled','Logoff Canceled by User',3)

    ; end verification

    If @OSARCH = "x86" Then
    $concenter = "C:\Program Files\Citrix\ICA Client\concentr.exe"
    Else
    $concenter = "C:\Program Files (x86)\Citrix\ICA Client\concentr.exe"
    EndIf

    Run($concenter)
    WinActivate("Citrix Connection Center")
    WinWaitActive("Citrix Connection Center")
    ;Give Connection Center enough time to populate the session information
    Sleep(3000)

    $hTreeView = ControlGetHandle("[Title:Citrix Connection Center]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
    $hItemRoot = _GUICtrlTreeView_FindItem($hTreeView, 'Active', True, 0 )
    $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItemRoot)

    ;Check for ICA sessions
    if $hFirstChild <> 0 Then
    $SiblingCount = _GUICtrlTreeView_GetSiblingCount($hTreeView, $hFirstChild)
    For $i = 0 To ($SiblingCount - 1) Step +1
    $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $hItemRoot,$i)
    $XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)
    ;MsgBox(0,"Result", $XenAPPSrv)
    ;Look for the required Server
    ;^WKENAH\w+ - WKENAH$$$$$215
    if StringRegExp($XenAPPSrv, "^WKENAH\w+", 0) = 1 Then
    ;MsgBox(0,"Result", "EPICSessionFound")
    ;RightClick on the ServerName
    _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "menu", False, 1)
    ;Send Logoff command
    Send("{Down 4}{Enter}")
    ;Confirm the logoff
    WinActivate("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
    WinWaitActive("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
    Send("&Yes")
    ;Work Done
    ExitLoop
    EndIf
    Next
    EndIf
    WinClose("Citrix Connection Center", "")
    Exit

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted
2 hours ago, kylomas said:

bballjoe12,

Try this...see comments...

#comments-start

    AutoIt Version: 3.0
    Language:       English
    Platform:       WinXP and above
    Author:         Siva Mulpuru (http://www.linkedin.com/in/sivamulpuru)
    Script Function:
    Logoff from a sepcific XenApp Server using connection center
    Tested with Receiver 3.x

    #comments-End
    #include <GuiTreeView.au3>

    ; verification

    if MsgBox(4, "Logoff", "Click YES to Logoff") <> 6 then exit msgbox(17,'Logoff Canceled','Logoff Canceled by User',3)

    ; end verification

    If @OSARCH = "x86" Then
    $concenter = "C:\Program Files\Citrix\ICA Client\concentr.exe"
    Else
    $concenter = "C:\Program Files (x86)\Citrix\ICA Client\concentr.exe"
    EndIf

    Run($concenter)
    WinActivate("Citrix Connection Center")
    WinWaitActive("Citrix Connection Center")
    ;Give Connection Center enough time to populate the session information
    Sleep(3000)

    $hTreeView = ControlGetHandle("[Title:Citrix Connection Center]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
    $hItemRoot = _GUICtrlTreeView_FindItem($hTreeView, 'Active', True, 0 )
    $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItemRoot)

    ;Check for ICA sessions
    if $hFirstChild <> 0 Then
    $SiblingCount = _GUICtrlTreeView_GetSiblingCount($hTreeView, $hFirstChild)
    For $i = 0 To ($SiblingCount - 1) Step +1
    $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $hItemRoot,$i)
    $XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)
    ;MsgBox(0,"Result", $XenAPPSrv)
    ;Look for the required Server
    ;^WKENAH\w+ - WKENAH$$$$$215
    if StringRegExp($XenAPPSrv, "^WKENAH\w+", 0) = 1 Then
    ;MsgBox(0,"Result", "EPICSessionFound")
    ;RightClick on the ServerName
    _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "menu", False, 1)
    ;Send Logoff command
    Send("{Down 4}{Enter}")
    ;Confirm the logoff
    WinActivate("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
    WinWaitActive("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
    Send("&Yes")
    ;Work Done
    ExitLoop
    EndIf
    Next
    EndIf
    WinClose("Citrix Connection Center", "")
    Exit

kylomas

Thank you so much!  It worked just as I needed!

Posted

Thank you so much everyone for the help!  I actually have another question now.  Would there be anyway to grab the text under the Connections heading?  That would include the 'Active' and 'CHIXACERDPRD145' line.  It looks like the information is inside of another window of that pop-up.  As I am very new to all of this, I was messing around with the following code and made some progress but can't figure out how to get information from the "inset" window (which if it is possible, I'd like to then copy that information).  Any ideas?

; Script Start - Add your code below here
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Retrieve the window text of the active window.
    Local $sText = WinGetText("Citrix Connection Center")

    ; Display the window text.
    MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

getinfo.png

Posted (edited)

I changed the StringRegExp for you, although I haven't tested it myself:

#cs

AutoIt Version: 3.0
Language:       English
Platform:       WinXP and above
Author:         Siva Mulpuru (http://www.linkedin.com/in/sivamulpuru)
Script Function:
                Logoff from a sepcific XenApp Server using connection center
                Tested with Receiver 3.x

#ce

#include <GuiTreeView.au3>
;MsgBox(0,"Result", @OSArch)
If @OSARCH = "x86" Then
    $concenter = "C:\Program Files\Citrix\ICA Client\concentr.exe"
Else
    $concenter = "C:\Program Files (x86)\Citrix\ICA Client\concentr.exe"
EndIf

Run($concenter)
WinActivate("Citrix Connection Center")
WinWaitActive("Citrix Connection Center")
;Give Connection Center enough time to populate the session information
Sleep(3000)

$hTreeView = ControlGetHandle("[Title:Citrix Connection Center]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
$hItemRoot = _GUICtrlTreeView_FindItem($hTreeView, 'Active', True, 0 )
$hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItemRoot)

;Check for ICA sessions
if $hFirstChild <> 0 Then
   $SiblingCount = _GUICtrlTreeView_GetSiblingCount($hTreeView, $hFirstChild)
   For $i = 0 To ($SiblingCount - 1) Step +1
      $hItem = _GUICtrlTreeView_GetItemByIndex($hTreeView, $hItemRoot,$i)
      $XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)
      ;MsgBox(0,"Result", $XenAPPSrv)
      ;Look for the required Server
      ;^WKENAH\w+ - WKENAH$$$$$215
      if StringRegExp($XenAPPSrv, "^CHIXACERDPRD\w+", 0) = 1 Then
         ;MsgBox(0,"Result", "EPICSessionFound")
         ;RightClick on the ServerName
          _GUICtrlTreeView_ClickItem($hTreeView, $hItem, "menu", False, 1)
          ;Send Logoff command
          Send("{Down 4}{Enter}")
          ;Confirm the logoff
          WinActivate("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
          WinWaitActive("[Title:Citrix Receiver; CLASS:NativeMessageWindowClass]", "")
          Send("&Yes")
          ;Work Done :)
          ExitLoop
      EndIf
   Next
EndIf
WinClose("Citrix Connection Center", "")
Exit

In this code the line "$XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)" should get you the text you want.

Edited by anthonyjr2
fixed an error

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Posted
8 hours ago, anthonyjr2 said:

I changed the StringRegExp for you, although I haven't tested it myself:

In this code the line "$XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)" should get you the text you want.

Anthony,

Sorry about all the questions.  I am totally new to all of this and it is still very complicated to me.  As you said that you changed the StringRegExp and also you said that the line "$XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)" would get the text I want, would I need to edit the code below to insert the "$XenAPPSrv = _GUICtrlTreeView_GetText($hTreeView, $hItem)" somewhere?

; Script Start - Add your code below here
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Retrieve the window text of the active window.
    Local $sText = WinGetText("Citrix Connection Center")

    ; Display the window text.
    MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

 

Posted

In what I posted, the variable $XenAppSrv would have the text you are looking for in it. If you wanted to use it elsewhere you'd just have to pass that variable.

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Posted
; Script Start - Add your code below here
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Retrieve the window text of the active window.
    Local $sText = WinGetText("Citrix Connection Center")

    ; Display the window text.
    MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

Can you show me Anthony how to put that $XenAppSrv as a variable into the above script?

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
  • Recently Browsing   0 members

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