18

I wrote some c# code that uses PSexe. I want it to run a remote exe on a machine connected to my LAN.

That exe creates a new local user. When I run that exe locally on the remote machine (after right click --> "run as Admin") - it works fine. I don;t know how to simulate the right click --> "run as Admin" from Psexec. I have tried the -l flag but it didn't work

2 Answers 2

36

Simply add a -h after adding your credentials using a -u -p, and it will run with elevated privileges.

4
  • psexec does not support the argument -h. At least not in the current version of 2009.
    – ygoe
    Commented Jun 26, 2013 at 12:28
  • 3
    @LonelyPixel Just came across this... the version I got here does have a -h parameter: If the target system is Vista or higher, has the process run with the account's elevated token, if available.
    – tnw
    Commented Sep 24, 2013 at 14:21
  • Interesting. Now I also get a version with "-h" from them. Must be an upgraded 1.98. But it fails if I'm not already calling it as admin. (Can't create service, access denied.) Where's the sense in that?
    – ygoe
    Commented Sep 24, 2013 at 19:05
  • This helped me, thank you! I had troubles with remotely executing appcmd to stop IIS sites. The error was: redirection.config Cannot read configuration file due to insufficient permissions. In case anyone has similar issues. Commented Jan 27, 2017 at 7:18
21

Use psexec -s

The s switch will cause it to run under system account which is the same as running an elevated admin prompt. just used it to enable WinRM remotely.

1
  • 14
    Sorry, this is just plain wrong. The SYSTEM account is something entirely different than you user account with all privilege tokens (including the administrative ones) enabled! The SYSTEM account is allowed to do everything (usually). Even things that a local administrator can't do. It's also a different user profile so it uses different settings and path names.
    – ygoe
    Commented Jun 26, 2013 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.