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).
Re: Windows runas command
by Anonymous Monk on Feb 14, 2010 at 15:48 UTC
|
| [reply] |
Re: Windows runas command
by NetWallah (Canon) 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
| [reply] [d/l] |
|
| [reply] |
|
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,
| [reply] |
|
|
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.
| [reply] |
|