Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I use PuTTY tools from a Perl script, in particular pscp (PuTTY scp), and I use Pageant for automated authentication, so that I don't have to type in my password for every single file to transfer.

But my Pageant uses a password to its vault, too. So Pageant must already be running and ready before I attempt to scp files, or I still have to type in my password, every time, manually.

And that's where this snippet comes in. It tries to start up Pageant, waits till it comes back and/or until you typed in the password and pressed return, and only then resumes.

I use Win32::Process to launch Pageant, and one of 2 things may happen:

  1. Pageant wasn't running and it will pop up a login dialog box asking for the password. And then, after the dialog box closes, the process will continue running in the background, with an icon in the systray. If you Wait for that process to finish, you can wait for a very long time...

  2. Pageant was already running in the systray and the process immediately exits.

So, what does the snippet do?

  1. It reads the parameters to launch Pageant with from a Windows shortcut file (*.lnk file) — You may skip this part.

  2. It launches Pageant using Win32::Process, and it waits for 2 seconds for it to finish. So, in case (2) it'll immediately return, but in case (1) it'll give the program enough time to show its password dialog window.

  3. It uses Win32::GuiTest to see if the password dialog is still up, and polls, and waits until it closes.

use Win32::Process; use Win32; use Win32::Shortcut; my $link = Win32::Shortcut->new; $link->Load("D:\\Program Files\\Putty\\start pageant.lnk"); $link->Close(); # print "Shortcut to: $link->{Path} $link->{Arguments}\nDirectory: + $link->{WorkingDirectory}"; Win32::Process::Create(my $process, $link->{Path}, qq("$link->{Path}" $link->{Arguments}), $link->{ShowCmd}, NORMAL_PRIORITY_CLASS, $link->{WorkingDirectory}) or die Win32::FormatMessage( Win32::GetLastError() ); require Win32::GuiTest; # while we're waiting... my $result = $process->Wait(2_000); # returns immediately if page +ant was running # times out if it just got st +arted up while(1) { my @windows = Win32::GuiTest::FindWindowLike(0, qr/^Pageant:\s ++Enter\s+Passphrase/i) or last; sleep 1; }

In reply to Win32: Launch and wait for Pageant before resuming by bart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found