OldMike Posted February 19, 2011 Share Posted February 19, 2011 (edited) I need to have four identical scripts running asynchronously. Each will open and run a session of the same application. Alternatively I could run a "for 1 to 4" thing and do them that way, then watch for each to need shutting down. I am running a test pgm and it is fine, using a ProcessWaitClose("name.ext") to verify that the program shuts down before moving on. But I can't use the service name because it will kill all four. All of the activate, kill, waitfor, etc, functions require a title or text to identify which is which, but I can't figure out how to control which session has which title or text, and franly can't figure out what they are anyway. I think when the program launches what is in the title bar is the title, but they will either all be the same or have an abritrary sequence number. So would like to force what goes into the title bar, then I can select it to give it focus ("activate"?) or just kill it. I can get the PID when I launch it, but none of the control functions accept PID. None of this is for human observation (unattended PCs), so could even just write the PID in as the title (text?) and then use that for granting focus and/or shutting down. OS = WIN7-64. Edited February 19, 2011 by OldMike Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 19, 2011 Share Posted February 19, 2011 For $i = 1 to 4 RunWait(@ScriptDir & "\Script" & $i & ".exe") Next My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
OldMike Posted February 19, 2011 Author Share Posted February 19, 2011 This runs separate scripts. What I need to do is launch four instances of the same Windows application (ABBYY; an OCR program). Therefore the name of the executable is the same each time. So I need to identify each session, then be able later on to gain (and keep) focus on any given one so that I can send it the key strokes to shut down gracefully. I think it would also work if I could just kill the running program, but I still need to specify which of the four sessions I am killing. Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 19, 2011 Share Posted February 19, 2011 (edited) Global $PID[5] For $i = 1 to 4 Run("Notepad.exe") Sleep(1000) WinSetTitle("Untitled - Notepad", "", "Notepad " & $i) ;New Title of Window Sleep(500) $PID[$i] = WinGetProcess("Notepad " & $i) ;PID of window stored as $PID[1], $PID[2], $PID[3], $PID[4] Next Edited February 19, 2011 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
OldMike Posted February 19, 2011 Author Share Posted February 19, 2011 (edited) Not sure about this. It returns the PID, but none of the focus functions seem to use PID; they use Title. How would this do: Global $TITLE[5] For $i = 1 to 4 Run("Notepad.exe") Sleep(1000) WinSetTitle("Untitled - Notepad", "", "Notepad " & $i) ;New Title of Window Sleep(500) Next ;now wait to detect that a given session is ready for key strokes to shut it down. Let's say I know it is number 3 WinActivate("Notepad 3") ;Send keystrokes to shut down WinWaitClose("Notepad 3") What confuses me is the examples that use [CLASS:Notepad.exe], when I need to use the specific title of the specific session. Mike Edited February 19, 2011 by OldMike Link to comment Share on other sites More sharing options...
BrewManNH Posted February 19, 2011 Share Posted February 19, 2011 Look at the code he wrote, it changes the title of the notepad window each time it runs notepad so you can keep track of it by the unique title. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
OldMike Posted February 20, 2011 Author Share Posted February 20, 2011 (edited) Title change is not working. I made a test program just for this, with a loop of one to keep it as simple as possible: #include<file.au3> #Include<array.au3> opt("WinTitleMatchMode",-3) For $i = 1 to 1 Run("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe") Sleep(3000) WinSetTitle("Untitled document - ABBYY FineReader 10 Professional Edition", "", "ABBYY" & $i) ;New Title of Window Sleep(5000) Next msgbox(0,"","Done") When I run it, the title at the top and icon in the bottom tray both change to "ABBYY1". But as soon as the program hits the msgbox step, the title goes back to "Untitled document - ABBYY FineReader 10 Professional Edition", top and bottom. It works fine with Notepad, but the title change does not 'stick' with ABBYY. If I don't have the msgbox at the end, then the title change sticks (and if the loop is more than once, it sticks on the last instance but not any previous), but as soon as I touch the mouse or any key, then the title reverts to the stock title. Edited February 20, 2011 by OldMike Link to comment Share on other sites More sharing options...
OldMike Posted February 20, 2011 Author Share Posted February 20, 2011 This latest issue is far off track from the original posting, so I will stop checking this thread and start a new one regarding changing the title. Thanks for all the help. Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 20, 2011 Share Posted February 20, 2011 (edited) WinTitleMatchMode - Alters the method that is used to match window titles during search operations. 1 = Match the title from the start (default) 2 = Match any substring in the title 3 = Exact title match 4 = Advanced mode, see Window Titles & Text (Advanced) -1 to -4 = force lower case match according to other type of match. You are using -3 which is "EXACT title match with forcing lower case but you are using uppercase letter?!? Try using Any Substring opt("WinTitleMatchMode", 2) with the following: Opt("WinTitleMatchMode", 2) For $i = 1 to 4 Run("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe") Sleep(3000) WinSetTitle("ABBYY", "", "ABBYY " & $i) ;New Title of Window Sleep(5000) Next MsgBox(0, "", "Done") Edited February 20, 2011 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
OldMike Posted February 20, 2011 Author Share Posted February 20, 2011 Doesn't change the title at all, not even temporarily. Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 20, 2011 Share Posted February 20, 2011 (edited) Doesn't change the title at all, not even temporarily.Downloaded Trail of FineReader Installing now will test functions ASAPBTW Installing this software takes forever..... Edited February 20, 2011 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 20, 2011 Share Posted February 20, 2011 (edited) So the window title does change temporarly screenshot below. But the problem is that program FineReader changes the title right back?!?Best bet would be to get PID.Global $PID[5] For $i = 1 to 4 $PID[$i] = Run("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe") Next ; OR For $i = 1 to 4 $PID[$i] = RunWait("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe") Next ProcessClose, ProcessExists, ProcessGetStats, ProcessList ProcessSetPriority, ProcessWait ; All Uses PID Edited February 20, 2011 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
OldMike Posted February 20, 2011 Author Share Posted February 20, 2011 I have versions of my program using PID, versions using handle. Getting them is not the problem. The problem is that the functions for forcing focus on an arbitrary session all are based on Title. I tried using handle where Title would go, but it does not work. And yes, once ABBYY is launched it reverts back, undoing the title I set. On the list of functions that use PID, none of them create focus. I need focus to send the key strokes (!f, x, n) that shut it down. Link to comment Share on other sites More sharing options...
OldMike Posted February 20, 2011 Author Share Posted February 20, 2011 Assuming I just can't get Title to work, tried using PID and it does not shut down: #include<file.au3> #Include<array.au3> Global $PID[5] For $i = 1 to 1 $PID[$i] = RunWait("C:\Program Files (x86)\ABBYY FineReader 10\FineReader.exe") Next Sleep(3000) ProcessClose($PID[1]) Launches, then does not shut down. Link to comment Share on other sites More sharing options...
OldMike Posted February 21, 2011 Author Share Posted February 21, 2011 Just to frame this up; I have had several suggestions of how to launch (this and another related posting) the four sessions, all of which work. But I need to be able to shut down an arbitrary session. All the focus and shutdown functions want to use Title, but Title doesn't stick with ABBYY. So I need a way to either get focus or shut down the process using PID or Handle or any other means. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 21, 2011 Moderators Share Posted February 21, 2011 OldMike,Stop bumping both your threads on the same subject! I have already answered in the other. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
OldMike Posted February 21, 2011 Author Share Posted February 21, 2011 A while ago they sort of diverged, so started the second. Not my intent to screw up the board. 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