adrianherscu Posted August 8, 2010 Share Posted August 8, 2010 Hi all, I need to launch to instances of the same application, each one in a separate process. I need a reliable way to find the main window of the application given the process identifier of the required instance. I have tried with the following code: Func system_WaitForWindow($windowTitle, $timeout = Default) Local $success = WinWait($windowTitle, $system_EMPTY_STRING, $timeout) system_AssertTrue($success, _ system_CreateMessage("WaitForWindow", $windowTitle, $timeout)) Return $success EndFunc ;==>system_WaitForWindow Func system_WindowFor($processId, $windowTitle, $timeout = Default) system_WaitForWindow($windowTitle, $timeout) Local $windowId, $i Local $windows = WinList($windowTitle) For $i = 1 to $windows[0][0] $windowId = $windows[$i][1] If $processId = system_ProcessOf($windowId) Then ExitLoop EndIf Next system_AssertTrue($windowId, system_CreateMessage( _ "WindowFor", $processId, $windowTitle, $timeout)) Return $windowId EndFunc ;==>system_WindowFor The problem with this code is that it is not reliable. It just takes some unpredictable time until the window of the required process becomes available. Just asking to wait for some window by its title is not enough. I need it to filter the results by process also. Any way to achieve this with AutoIt? Please help, Adrian. Link to comment Share on other sites More sharing options...
taietel Posted August 8, 2010 Share Posted August 8, 2010 (edited) Welcome to the forum, adrianherscu! Maybe this gives you some ideas: #include <Process.au3> $PID1 = Run("notepad.exe") $PID2 = Run("notepad.exe") If ProcessExists($PID1) Then ;do something ConsoleWrite("Ooops! There is! Instance no.1:" & $PID1 & "; Executable: " & _ProcessGetName($PID1) & @CRLF) EndIf If ProcessExists($PID2) Then ;do something ConsoleWrite("Ooops! There is! Instance no.2:" & $PID2 & "; Executable: " & _ProcessGetName($PID2) & @CRLF) EndIf Edited August 8, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
adrianherscu Posted August 9, 2010 Author Share Posted August 9, 2010 Hmmm... Seems that a better explanation is required. I need to test some App that updates a database. My plan is to launch two instances of App, App1 and App2, each one running in its own process. Then, I would be able to create/read/update/delete a record in App1 and test that this change can be retrieved in App2. When AppX process begins to run it creates the main App window, AppWindowX, titled "App". Since AppX needs to initialize various internal things this behavior is time dependent, hence the test needs to block until a window titled "App" appears. Then I have: App1 --> creates --> AppWindow1 (titled "App") <-- the test must block until this window appears App2 --> creates --> AppWindow2 (titled "App") <-- the test must block until this window appears too Using the WinWait function is not enough since both windows have the same title. Any way to do it with AutoIt built-in functions or do I need to call Win32 APIs? Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 9, 2010 Share Posted August 9, 2010 Hi, what about WinSetTitle? After that you can distinguish between the AppWindows by name. Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times 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