Jump to content

How to create a Yes/No Window? I'm a Newbie!


Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

@bballjoe12 How about pasting your code here so we can try to help rather than having us guess? ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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=

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

; 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?

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...