title: How to spawn a process as another user on Windows?
body: <p>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&mdash;I would use hammer if it worked.</p>
  
  <p>What I've tried so far is</p>
  
  <pre><code>$cmd = 'runas /user:tester01 "perl delegated.pl"';
  system($cmd) == 0
      or die "could not spawn process as tester01: $!";
  </code></pre>
  
  <p>but that does not work: it asks for password interactively. (Piping <code>echo password</code> into the <code>runas</code> failed as well.)</p>
  
  <p>How should I achieve it from within Perl script?  Or should I do something else before that <code>system "runas..."</code> part?</p>
  
  <p>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.</p>