Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
The stupid question is the question not asked
 
PerlMonks  

Windows runas command

by flintstone (Initiate)
on Feb 14, 2010 at 15:39 UTC ( #823136=perlquestion: print w/ replies, xml ) Need Help??
flintstone has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have been trying to discover a way of doing the following on Windows !. I need to be able to call the windows 'runas' command from a perl script to switch users. Ok that part is easy. Problem is with runas is it requires that the password be entered interactivly which is obviously a pain if you are trying to run it as part of a script. I have toyed with using 'except and react'. However, have not been able to find modules\versions that will run on windows or had any luck using ppm to download. Thought about trying to download the source and compile the required modules but not sure about which compiler to use on windows or if there is a possibility this would work anyway Does anyone have any ideas on the best way to proceed or a suggestion on how I can respond to the password prompt via a script on windows (2000,XP,2003,2008).

Comment on Windows runas command
Re: Windows runas command
by Anonymous Monk on Feb 14, 2010 at 15:48 UTC
Re: Windows runas command
by NetWallah (Monsignor) on Feb 14, 2010 at 17:54 UTC
    Untested (I'm away from my PC), but provides the general idea:
    my $User="Somebody"; my $Pass="ThisIsInsecure!"; my $Program_to_run="notepad.exe"; my $result=`echo $Pass|RunAs /User:$User $Program_to_run`;
    If the command prompt is not invoked correctly, you may need to add a "cmd/c " before the "echo".

         Theory is when you know something, but it doesn't work.
        Practice is when something works, but you don't know why it works.
        Programmers combine Theory and Practice: Nothing works and they don't know why.         -Anonymous

      That is insecure as the password would show in processexplorer(taskmanager)

      What you want is to follow VBS shell code, use Win32::GuiTest or Win32::OLE

        Hi, Thanks for the reply. I am afraid I have to grovel a bit as I am new to Perl and would not have much of an idea of how to best use the modules you mention. Is is possible you could supply an exmple of how they could be used to invoke the runas command.That would be really appreciated,
      Hi, Thanks for the suggestion. Gave it a try but basically its the same as things I have tried to do with echo and redirection.It seesms its not possible do do this with Runas. As I mentioned I had considered the React or Expect modules to respond to the password prompt but could not find workable modules for Windows.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-04-18 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls