Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
go ahead... be a heretic
 
PerlMonks  

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>runas.pl 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?

http://www.basgetti.com

Comment on Runas using open
Select or Download Code
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?
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,
    Zaxo

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...

      http://www.basgetti.com

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-04-21 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls