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

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

36

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

transistor1
  • 2,915
  • 26
  • 42
Chisman
  • 361
  • 3
  • 2
  • psexec does not support the argument `-h`. At least not in the current version of 2009. – ygoe Jun 26 '13 at 12:28
  • 3
    @LonelyPixel Just came across this... the version I got [here](http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) 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 Sep 24 '13 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 Sep 24 '13 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. – Jurijs Kastanovs Jan 27 '17 at 07:18
22

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.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
  • 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 Jun 26 '13 at 12:26