Sign in to follow this  
Followers 0
rudi

$PID=run("AcroRd32.exe") -> how to address the Window this is "creating"?

13 posts in this topic

#1 ·  Posted (edited)

Hi.

I think I've seen this here before, but when I was searching for "+PID +window" I didn't find anything? :)

I'm writing a small tool helping the users to rename Scan2FTP PDF documents.

It's basically searching all files in a given folder, and if the name pattern doesn't match "^\d{5}-\d{2}\.PDF$" (5 digits, - , 2 digits, .PDF), then I want to open Acrobat Reader to readup some information inside the PDF the file name has to be made of, then close the opended PDF and rename it.

This renaming is working fine fine so far. What I want is to leave the Acrobat Reader open all the time to speed up the "open PDF".

So

$ARPID=run(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Software\Adobe\Acrobat\Exe",""))

will give me the PID of the opened reader. Then I want to close JUST the opened PDF document without exiting the Reader, but how to address the "inner" frame to close the PDF document (e.g. click the "inner" [x] or to send CTRL+F4) using the PID, and how to control if all open PDF's ARE closed?

Any suggestions appreciated, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



Hi.

I think I've seen this here before, but when I was searching for "+PID +window" I didn't find anything? :)

I'm writing a small tool helping the users to rename Scan2FTP PDF documents.

It's basically searching all files in a given folder, and if the name pattern doesn't match "^\d{5}-\d{2}\.PDF$" (5 digits, - , 2 digits, .PDF), then I want to open Acrobat Reader to readup some information inside the PDF the file name has to be made of, then close the opended PDF and rename it.

This renaming is working fine fine so far. What I want is to leave the Acrobat Reader open all the time to speed up the "open PDF".

So

$ARPID=run(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Software\Adobe\Acrobat\Exe",""))

will give me the PID of the opened reader. Then I want to close JUST the opened PDF document without exiting the Reader, but how to address the "inner" frame to close the PDF document (e.g. click the "inner" [x] or to send CTRL+F4) using the PID, and how to control if all open PDF's ARE closed?

Any suggestions appreciated, Rudi.

I haven't got Acrobat Reader but I have got Adobe Reader and maybe the behavior is similar enough to make the following sensible.

When AR has no open files the window title is 'Adobe Reader'. When there is a file open the title changes to 'Document name - Adobe Reader'

So if there is a Window with Adobe Reader in the Title you can do this. (Tested on Adobe Reader.)

Opt("WInTitleMatchMode", 2);so we can match part of the title
$closedOne = True;truie just to get the while/wend loop started
While $closedOne
    $closedOne = False
    $ARtitle = WinGetTitle("Adobe Reader")
    ConsoleWrite($ARtitle & @CRLF)
    If IsString($ARtitle) Then;window exists
        If StringInStr($ARtitle, "- Adobe Reader") Then;a document is open
            WinActivate($ARtitle);in case it wasn't active
            sleep(200)
            Send("!f");select file menu
            Sleep(100);don't know if this is needed
            Send("c");close file
            $closedOne = True
        EndIf
    EndIf
WEnd
;now AR is running but with no files open

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I haven't got Acrobat Reader but I have got Adobe Reader and maybe the behavior is similar enough to make the following sensible.

You are right, the "Adobe Acrobat Reader" is just called "Adobe Reader" now :), IIRC it was called "Adobe Acrobat Reader" some time? :P

The EXE name still points to the fact, that it's the reader for "Acrobat documents" = PDF files: AcroRd32.exe :P

When AR has no open files the window title is 'Adobe Reader'. When there is a file open the title changes to 'Document name - Adobe Reader'

That's the way I didn't mean to do it. Well, for AcroRd32.exe this would do, as this program will run only a single instance.

So pls. let me ask more precisely:

1.) how to address a Window through it's PID?

2.1) how to check if such an application (AR, Winword, Excel, ...) has documents open in it ("inner" window)?

2.2) how to address a "inner" window within such an application, that might have opened several "inner" windows? (like AR or WinWord or Excel?)

Thanks, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

You are right, the "Adobe Acrobat Reader" is just called "Adobe Reader" now :), IIRC it was called "Adobe Acrobat Reader" some time? :P

The EXE name still points to the fact, that it's the reader for "Acrobat documents" = PDF files: AcroRd32.exe :P

That's the way I didn't mean to do it. Well, for AcroRd32.exe this would do, as this program will run only a single instance.

So pls. let me ask more precisely:

1.) how to address a Window through it's PID?

2.1) how to check if such an application (AR, Winword, Excel, ...) has documents open in it ("inner" window)?

2.2) how to address a "inner" window within such an application, that might have opened several "inner" windows? (like AR or WinWord or Excel?)

Thanks, Rudi.

I would also like to know how to address a window by its pid, I currently am trying to work with 2 different windows that have the same name. . . I already tried to rename the windows but inside the program the name of the window is updated frequently making it damn near impossible to keep both programs named.

Share this post


Link to post
Share on other sites

I would also like to know how to address a window by its pid, I currently am trying to work with 2 different windows that have the same name. . . I already tried to rename the windows but inside the program the name of the window is updated frequently making it damn near impossible to keep both programs named.

ProcessList gets a list of exe names and their PIDs.

WinGetProcess gets a list of window titles and their PIDs, so it just needs a loop to tie up window tiltles, exe names and PID's.

To find child windows search for EnumChildWindows.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

ProcessList gets a list of exe names and their PIDs.

WinGetProcess gets a list of window titles and their PIDs, so it just needs a loop to tie up window tiltles, exe names and PID's.

To find child windows search for EnumChildWindows.

WinGetProcess() only returns the PID of a single window, so you'll have to do WinList(), then use the handles from that list to check each PID with WinGetProcess() in a loop until you find a match.

The problem in this particular case is Adobe. They like to spin off multiple windows that won't match up neatly with your Run() PID at all. Adobe reader opens a window called "DDE Server Window" and hidden windows with no title at all.

Run this with Acrobat already open:

#include <Array.au3>

$avWin = WinList()
ReDim $avWin[$avWin[0][0] + 1][3]
For $n = 1 To $avWin[0][0]
    $avWin[$n][2] = WinGetProcess($avWin[$n][1]); Use HWnd to get PID
Next
_ArrayDisplay($avWin, "$avWin: Title/HWnd/PID")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hi.

#include <Array.au3>

$avWin = WinList()
ReDim $avWin[$avWin[0][0] + 1][3]
For $n = 1 To $avWin[0][0]
    $avWin[$n][2] = WinGetProcess($avWin[$n][1]); Use HWnd to get PID
Next
_ArrayDisplay($avWin, "$avWin: Title/HWnd/PID")

Thanks.

I was just wondering if there might be some solution to directly address a window when I already know it's PID.

$PID=run("Some.EXE")

I think I'll use your approach :)

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

I was just wondering if there might be some solution to directly address a window when I already know it's PID.

$PID=run("Some.EXE")
The bad assumption there is that you have a single window for a given PID. There can be many windows per PID.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The bad assumption there is that you have a single window for a given PID. There can be many windows per PID.

OK. I missed that aspect, as for Acrobat Reader there is (AFAIK) always exactly one window. Also AR is a "singleton" prog.

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

OK. I missed that aspect, as for Acrobat Reader there is (AFAIK) always exactly one window. Also AR is a "singleton" prog.

Regards, Rudi.

You can "See" exactly one window.

There are some hidden windows to that PID as well though. You would have to check the window state for every window for that PID.

Share this post


Link to post
Share on other sites

OK. I missed that aspect, as for Acrobat Reader there is (AFAIK) always exactly one window. Also AR is a "singleton" prog.

Regards, Rudi.

Did you run the demo in post #6? If you run that while you have Acrobat open, I think you'll get a surprise.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Did you run the demo in post #6? If you run that while you have Acrobat open, I think you'll get a surprise.

Well, I get an 2D array, 127+1 Rows, 3 Colls.

1.) There is one single entry ([41][0]) giving me "Adobe Reader".

2.) Another one is "_acroT_win", (not sure what that is...)

3.) and three times "Acrobat IEHelper", with three IE6 windows opened right now.

What should be a surprise for me here? :) I miss it :P

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Well, I get an 2D array, 127+1 Rows, 3 Colls.

1.) There is one single entry ([41][0]) giving me "Adobe Reader".

2.) Another one is "_acroT_win", (not sure what that is...)

3.) and three times "Acrobat IEHelper", with three IE6 windows opened right now.

What should be a surprise for me here? :P I miss it :P

Regards, Rudi.

My suspicion was there would be entries with the same PID in the third column, but names you didn't expect that don't have "Adobe" or "Acrobat" anywhere in them, like "DDE Server". That's why I added that column to the array. Did you look for matching PIDs?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0