Jump to content

Is it possible to use Autoit to detect when a Windows dialog opens?


SDC
 Share

Recommended Posts

This is the scenario. Within Windows, I run a support ticket application that causes an inactivity dialog (Windows OS based dialog) to popup every 5-10min. The dialog allows the user to click "logoff" or "stayed logged in". In most cases, I want to stay logged in. If the "stay logged in" button is clicked, it forces focus to the ticket application. This gets very annoying because most of the time I'm interacting within another window.

Is it possible to write an Autoit script that can detect when this dialog is created (or made visible) and if so, auto click the "stay logged in" button. I would also like to keep focus on the current window.

Any help to point me in the right is greatly appreciated!

SDC

 

Link to comment
Share on other sites

  • Moderators

Is it possible? Yes. The ease with which you do so depends on the way the app was written. If you look in the directory where you installed AutoIt you will find the AutoIt Window Info Tool. Open this and then hover the bullseye icon over the pop up window. Post the information you get from the tool here and we will do our best to assist.

"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

Hi JLogan3o13! As noted in your reply, here is the captured info. None of the other sections within the summary had information it, so I only included the "Window"  details.

Thanks!

>>>> Window <<<<
Title:    Cherwell Inactivity Warning (VWNPR329.bcacd001.atl.**********.ca)
Class:    RAIL_WINDOW
Position:    167, 219
Size:    467, 176
Style:    0x16080000
ExStyle:    0x00040008
Handle:    0x002804AE

Link to comment
Share on other sites

  • Moderators

First off, as a former Cherwell admin, you have my sympathies.  So when you hove over the "Stay logged in option" the Window Info Tool returns nothing, correct?

"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

I'm not a big fan of Cherwell neither. That is correct, nothing is returned within the Window Info Tool when the buttons are hovered over. I've only been messing around with Autoit for the last hour or so. I can initiate some logic when the Cherwell inactivity dialog opens, but I assume I may not have direct access to the dialog buttons after that.

Thanks!

SDC

 

Link to comment
Share on other sites

  • 2 weeks later...

I actually wrote an application that I gave the creative name of "KeepCherwellLoggedIn" and it works great. Just looks for the Cherwell login window to open. If you notice, the default button of the two is "Stay Logged In", so I just set it to press the "Enter" key when the window appears. I have several co-workers who use the app as well. It works well. If you want, I can post the code here.

Who lied and told you life would EVER be fair?

Link to comment
Share on other sites

save this as keepalive.vbs (vbscript file) and run it inside your citrix desktop (which hopefully you can).
The 60000 is to wait 60.000 milliseconds so 60 seconds = 1 minute before hitting numlock key up and down to keep system alive.

Set WxhShell = CreateObject("WScript.Shell")


while 1
    
    WxhShell.SendKeys "{NUMLOCK}"
    WxhSHELL.sendkeys "{SCROLLLOCK}"
        wscript.sleep(1000)
    WxhSHELL.sendkeys "{SCROLLLOCK}"
    WxhShell.SendKeys "{NUMLOCK}"
    wscript.sleep(60000)

wend

 

Link to comment
Share on other sites

  • 3 months later...
On 9/30/2017 at 0:12 AM, benched42 said:

I actually wrote an application that I gave the creative name of "KeepCherwellLoggedIn" and it works great. Just looks for the Cherwell login window to open. If you notice, the default button of the two is "Stay Logged In", so I just set it to press the "Enter" key when the window appears. I have several co-workers who use the app as well. It works well. If you want, I can post the code here.

@benched42

Hi, I am trying to write a script just like that, to detect a similar dialog window that pops-up and need to close it automatically. Can you share your script, please?

Thank you.

L.E. I have made a script that works, but I would like to make it work also in the case if the workstation is locked or screensaver comes up.

Edited by replaygeorge
Link to comment
Share on other sites

22 minutes ago, Earthshine said:

Windows dialogs are Class #32770 or something.

In my case the class is SunAwtFrame (I think Java related).

Here is the script that I made, to detect this window:

AutoItSetOption("MouseCoordMode", 0) ; relative coords to active window

While 1

$hWnd =  WinGetHandle ( "My window" )

If WinExists ("My window") Then

   WinActivate ("My window")

   MouseClick ( $MOUSE_CLICK_PRIMARY, 205, 105, 1)   ; click on the OK button relative coords

EndIf

Sleep(5000) ; sleep (pause script) 5 seconds

WEnd

It works, but only if the screen is on. I cannot access the button, because of this class, so I need to click the mouse like that.

If the station is locked, it does not work. I need to run a process unattended, so the script should work even if the screen is off. Any suggestions?

Link to comment
Share on other sites

@replaygeorge  Here's the code. I tend to use comments and descriptive variable names so that if the code needs refreshing in the future I can remember what is actually going on.... :'(

 

; ===============================================================================================================================
; AutoIt3 Script
;
; KeepCherwellLoggedIn
;
; Script to check for the Cherwell Inactivity Warning window and if it exists, click on the "Stay Logged In" button
; Will check every 10 minutes for the window
;
; 2017-04-24 * Added log file in the user's My Documents folder
;            * Added the version to the "About" window
; 2017-04-25 * Fixed a bug in the file creation loop
; 2017-04-27 * Added code to determine if the workstation is locked. If it's locked we won't do anything.
; 2017-05-15 * Changed to using ControlSend()
; 2017-10-02 * Added the ability to turn off and turn on logging
; 2017-10-03 * Added the ability to run at Windows startup
; ===============================================================================================================================

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <TrayConstants.au3>

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  #AutoIt3Wrapper_Icon="C:\Users\HiltonB\Documents\ISN AutoIt Studio\MyScripts\KeepCherwell\img\keep.ico"
  #AutoIt3Wrapper_Compression=4
  #AutoIt3Wrapper_UseUpx=y
  #AutoIt3Wrapper_UseX64=N
  #AutoIt3Wrapper_Res_Description=Keep Cherwell Logged In
  #AutoIt3Wrapper_Res_Fileversion=2017.10.2
  #AutoIt3Wrapper_Res_LegalCopyright=2017
  ;#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Opt("TrayMenuMode", 3)
Global Const $DESKTOP_SWITCHDESKTOP = 0x0100

$frmSettings = GUICreate("Keep Cherwell Logged In", 300, 190, -1, -1, $WS_BORDER)
GUISetFont(10, 400, 0, "Segoe UI")
GUISetBkColor(0xDCDCDC)
GUICtrlCreateLabel("Settings", 15, 10, 280, 25)
GUICtrlSetFont(-1, 14, 800)
$chkStartWithWindows = GUICtrlCreateCheckbox(" Launch when Windows starts", 40, 50, 220, 20)
$chkUseLogFile = GUICtrlCreateCheckbox(" Use a log file", 40, 80, 220, 20)
$btnSave = GUICtrlCreateButton("Save", 100, 130, 90, 25)
$btnClose = GUICtrlCreateButton("Close", 200, 130, 90, 25)

$frmAbout = GUICreate("Keep Cherwell Logged In", 300, 190, -1, -1, $WS_BORDER)
GUISetFont(10, 400, 0, "Segoe UI")
GUISetBkColor(0xDCDCDC)
GUICtrlCreateLabel("Keep Cherwell Logged In!", 10, 40, 280, 30, $SS_CENTER)
GUICtrlSetFont(-1, 14, 800)
GUICtrlCreateLabel("v2017.10.02", 5, 144, 100, 20)
GUICtrlSetColor(-1, 0xA0A0A0)
GUICtrlSetFont(-1, 8, 400)
$btnOK = GUICtrlCreateButton("OK", 200, 130, 90, 25)

TraySetToolTip("Keep Cherwell Logged In")

$tSettings = TrayCreateItem("Settings")
TrayCreateItem("")
$tLogFileView = TrayCreateItem("View Log File")
TrayCreateItem("")
$tAbout = TrayCreateItem("About")
TrayCreateItem("")
$tExit = TrayCreateItem("Exit")

; Create the folder for the log file and then write one line in the log file
If Not FileExists(@MyDocumentsDir & "\KCLI") Then
  DirCreate(@MyDocumentsDir & "\KCLI")
  Sleep(200)
EndIf
$theLogFile = FileOpen(@MyDocumentsDir & "\KCLI\" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt", 1)
FileWriteLine($theLogFile, "Keep Cherwell Logged In launched at " & @HOUR & ":" & @MIN & @CRLF)
FileClose($theLogFile)

TraySetState($TRAY_ICONSTATE_SHOW)

$theTimer = TimerInit()
While 1
  Switch TrayGetMsg()
    Case $tAbout
      GUISetState(@SW_SHOW, $frmAbout)
      While 1
        Switch GUIGetMsg()
          Case $btnOK
            ExitLoop
        EndSwitch
      WEnd
      GUISetState(@SW_HIDE, $frmAbout)
    Case $tSettings
      If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "KeepCherwellLoggedIn") = "" Then
        GUICtrlSetState($chkStartWithWindows, $GUI_UNCHECKED)
      Else
        GUICtrlSetState($chkStartWithWindows, $GUI_CHECKED)
      EndIf
      If RegRead("HKEY_CURRENT_USER\Software\Trebuchet", "KCLILogFile") = "Yes" Then
        GUICtrlSetState($chkUseLogFile, $GUI_CHECKED)
      Else
        GUICtrlSetState($chkUseLogFile, $GUI_UNCHECKED)
      EndIf
      GUISetState(@SW_SHOW, $frmSettings)
      While 1
        Switch GUIGetMsg()
          Case $btnSave
            If GUICtrlRead($chkStartWithWindows) = $GUI_CHECKED Then
              RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "KeepCherwellLoggedIn", "REG_SZ", Chr(34) & @ScriptDir & "\KeepCherwellLoggedIn.exe" & Chr(34))
            Else
              RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "KeepCherwellLoggedIn", "REG_SZ", "")
            EndIf
            If GUICtrlRead($chkUseLogFile) = $GUI_CHECKED Then
              RegWrite("HKEY_CURRENT_USER\Software\Trebuchet", "KCLILogFile", "REG_SZ", "Yes")
            Else
              RegWrite("HKEY_CURRENT_USER\Software\Trebuchet", "KCLILogFile", "REG_SZ", "No")
            EndIf
            MsgBox(64, "Settings Saved", "The selected settings were changed.")
            ExitLoop
          Case $btnClose
            MsgBox(64, "No Changes", "No settings were changed.")
            ExitLoop
        EndSwitch
      WEnd
      GUISetState(@SW_HIDE, $frmSettings)
    Case $tLogFileView
      $theDefaultTextEditor = RegRead("HKEY_CLASSES_ROOT\txtfile\shell\open\Command", "")
      If FileExists(@MyDocumentsDir & "\KCLI\" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt") Then
        Run($theDefaultTextEditor & " " & @MyDocumentsDir & "\KCLI\" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt")
      Else
        MsgBox(64, "Information", "No log file exists yet!")
      EndIf
    Case $tExit
      ExitLoop
  EndSwitch
  $theElapsedTime = TimerDiff($theTimer)
  If $theElapsedTime > 60000 Then
    ; Checking every minute
    If WinExists("Cherwell Inactivity Warning") Then
      ; If the window exists, check to see if the workstation is locked
      WinActivate("Cherwell Inactivity Warning")
      ;ControlFocus("Cherwell Inactivity Warning","Stay Logged In",206196)
      ; Used the Au3Info tool to get the controlID for the button
      ;Send("{ENTER}")
      ControlSend("Cherwell Inactivity Warning", "Stay Logged In", "", "{ENTER}")
      ; Now add to log file if the user selected to use the log file
      If RegRead("HKEY_CURRENT_USER\Software\Trebuchet", "KCLILogFile") = "Yes" Then
        $theLogFile = FileOpen(@MyDocumentsDir & "\KCLI\" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt", 1)
        FileWriteLine($theLogFile, "Keep Cherwell Logged In ran at " & @HOUR & ":" & @MIN & @CRLF)
        FileClose($theLogFile)
      EndIf
    EndIf
    ; Reinitialize the timer
    $theTimer = TimerInit()
  EndIf
WEnd

$theLogFile = FileOpen(@MyDocumentsDir & "\KCLI\" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt", 1)
FileWriteLine($theLogFile, "Keep Cherwell Logged In exited at " & @HOUR & ":" & @MIN & @CRLF)
FileClose($theLogFile)

Exit

 

Who lied and told you life would EVER be fair?

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