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!