Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Win32::GuiTest process id

by leonidlm (Pilgrim)
on Nov 11, 2009 at 10:20 UTC ( [id://806453]=perlquestion: print w/replies, xml ) Need Help??

leonidlm has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I searched all the documentation and all the threads here in a solution to one simple task:
I want to run a specific gui program, get it's pid and automate only this program (the problem is that on the same machine someone can use the same program with the same caption, this is why I need to match between the window handlers returned by findWindowLike() procedure of win32::GuiTest to the PID of the process I just executed).
Does someone succeeded in doing so in the past ?

Replies are listed 'Best First'.
Re: Win32::GuiTest process id
by cdarke (Prior) on Nov 11, 2009 at 11:12 UTC
    When you run the program use Win32::Process::Create (bundled with ActiveState Perl). This sets a process object, and you can call a GetProcessID() method on it to get the PID.
      Yes, thank you!
      The problem is how I perform the findWindowLike() from the Win32::GuiTest module with the PID of the newly created process instead of the "window caption" regular expression.
      I want to automate only the window of the program I run and not some other instance of it!
Re: Win32::GuiTest process id
by Anonymous Monk on Nov 11, 2009 at 18:50 UTC
      Thank you. I used the second approach.
      And to share that knowledge with other monks I attach the final code I used:
      use Win32::API; use Win32::guiTest qw( :ALL ); my ($repMainWindow) = FindWindowLike(undef, "Caption") or die $!; Win32::API::->Import("user32","DWORD GetWindowThreadProcessId( HWND hW +nd, LPDWORD lpdwProcessId)") or die $^E; my $pidLPDWORDStruct = pack( "L", 0 ); GetWindowThreadProcessId($repMainWindow, $pidLPDWORDStruct); my ($pid) = unpack ("L", $pidLPDWORDStruct);
      Thanks for everyone who helped!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://806453]
Approved by wfsp
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2026-03-08 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.