I have a Perl script and I need to run it as another user on the local box. It’s a testing machine, so no real security—I would use hammer if it worked.
What I’ve tried so far is
$cmd = 'runas /user:tester01 "perl delegated.pl"';
system($cmd) == 0
or die "could not spawn process as tester01: $!";
but that does not work: it asks for password interactively. (Piping echo password into the runas failed as well.)
How should I achieve it from within Perl script? Or should I do something else before that system "runas..." part?
I know I can use PsExec, but I’d prefer Windows native solution. Currently the boxes it should work on are Windows 7 and Windows XP, but other Windows OS might be added later.
If you don’t want to play with WinAPI to send a password into the spawned shell (for example, Win32::GuiTest SendKeys method might be useful), you’d better use PsExec. ) This thread is a bit old, but it still describes Microsoft policy pretty well, I guess.