CyberRat Posted August 1, 2013 Share Posted August 1, 2013 I am writing a script to keep a Citrix session alive while using an app that only exposes it's UI as an Explorer add-in. This app is run as a seamless window to the client. The problem is that Citrix/MS ignores the explorer.exe process and will log the user out after 30 minuntes if only an explorer process is running. So, here comes an Autoit script to the rescue. My Script launches the explorer window and then stays open as long as it sees a visible window that has explorer.exe as it's process. The script works flawlessly thus far and stays open until the last explorer window is closed in that particular session, until I add a check to see if it is already running. There is no use in having more than one of the processes running per session. Unfortunately checking for the process itself is problematic because the built-in "ProcessList" and "ProcessExists" functions won't limit themselves the just that user session, they look at the whole server, that could have up to 14 other users running the exact same script on it and using WMI to check the ownership of the process is really slow. So I decided to create a hidden window as part of this script called RunningDocsLauncher. Then at the beginning of the script I do a "If Not WinExists("RunningDocsLauncher") then". Here is where I have a problem. If the eDocs window does not exist, but the back-end processes are running, the script launches the explorer window and then exits (it should stay in memory at this point). If I launch it a second time, it launches a second explorer window and then stays in memory and all subsequent launches run an additional explorer window and then properly exit. If I remove the WinExists condition and the requisite EndIf, the first launch stays in memory, but then all subsequent launches stay in memory as well. Any ideas as to why adding the WinExists causes the first launch to exit instead of staying in memory? expandcollapse popup#include <Process.au3> opt("WinTitleMatchMode",3) ;Launch explorer with a new window pointing at the eDocs node Run("C:\Windows\explorer.exe /n, ::{4577EA30-A1DF-11D0-BA3E-00A024746296}") ;Check to see if the hidden window does not exist, continue if it does not exist If not WinExists("RunningDocsLauncher") Then ;Create the hidden window $hWindow = GUICreate("RunningDocsLauncher") TraySetToolTip("Waiting for eDocs window...") ;Wait 60 seconds for the "eDocs" window to appear If WinWait("eDocs","",60) Then opt("TrayIconHide",1) ;Check to see if a window is visible that is created by explorer.exe While IsExplorerRunning() Sleep(250) WEnd Else ;if the eDocs window does not appear, check for the logon window and wait for it to close (Docs Supervisors must login to the system) While WinExists("Logon") TraySetToolTip("Waiting for eDocs logon...") Sleep(250) WEnd TraySetToolTip() If WinWait("eDocs","",10) Then While IsExplorerRunning() Sleep(250) WEnd EndIf EndIf GUIDelete($hWindow) EndIf Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Func IsExplorerRunning() $Windows = WinList() $ExplorerRunning = 0 For $i = 1 to $Windows[0][0] If IsVisible($Windows[$i][1]) Then $ProcessName = StringLower(_ProcessGetName(WinGetProcess($Windows[$i][0]))) If $ProcessName = "explorer.exe" then $ExplorerRunning = 1 ExitLoop EndIf EndIf Next Return $ExplorerRunning EndFunc Link to comment Share on other sites More sharing options...
FireFox Posted August 1, 2013 Share Posted August 1, 2013 Hi,Welcome to the autoit forum You could list the processes and associate an ID with its owner so that you don't have to query the owner unless there is a new instance of the process.Br, FireFox. Link to comment Share on other sites More sharing options...
CyberRat Posted August 1, 2013 Author Share Posted August 1, 2013 Thanks Firefox. I'll consider that. I think i found my problem. I inserted a short sleep right before I check for explorer running a window and that seems to have cleared up the issue. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now