Jump to content

Rookie question about Title, Text, PID


OldMike
 Share

Recommended Posts

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

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

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

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

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 Gude
How 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

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

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

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

Posted Image

Edited by rogue5099
Link to comment
Share on other sites

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

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

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

  • Moderators

OldMike,

Stop bumping both your threads on the same subject! :)

I have already answered in the other. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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