Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Runas using open

by slloyd (Hermit)
on Jun 12, 2005 at 01:58 UTC ( #465886=perlquestion: print w/replies, xml ) Need Help??
slloyd has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to pass in the password to the runas program. Shouldn't this work?
my $exe='myprogram.exe'; my $user='tester'; my $pass='lab'; my $cmd=qq|runas /profile /user:$user "$exe"|; open(FH,"| $cmd") || die $^E; print FH $pass; close(FH);
It does not seem to be sending the password. I get the following output:
H:\Products\Sandbox> Enter the password for tester: Attempting to start myprogram.exe as user "GUYBOX\tester" ... RUNAS ERROR: Unable to run - myprogram.exe 1326: Logon failure: unknown user name or bad password.
What am I doing wrong?

Replies are listed 'Best First'.
Re: Runas using open
by BrowserUk (Pope) on Jun 12, 2005 at 02:28 UTC

    runas.exe does not read passwords from stdin. It uses a call, CredUICmdLinePromptForCredentials() from a system dll that accesses the console directly. I assume that this is designed as a security measure.

    You may be able to use Win32::Console to obtain a handle to the current console and the WriteInput() method to drive the program. This is an untested idea.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Till now, I have never used Win32::Console. I tried a bunch of things but could not get anything to work...
Re: Runas using open
by Zaxo (Archbishop) on Jun 12, 2005 at 02:09 UTC

    This is probably from some form of command line interpretation doing unexpected things. Stick a print $cmd, "\n"; in there to see what you get, and try pasting that into the command line to see what happens.

    It might fix things to construct the command as an array and use the list form of 3+ arg open.

    After Compline,

Re: Runas using open
by monarch (Priest) on Jun 12, 2005 at 02:07 UTC
    Did you just ask this question before? Perhaps it's best to wait for an appropriate answer in that thread?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://465886]
Approved by monkfan
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-06-25 16:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (127 votes). Check out past polls.