-2

I want to run a PSExec action, that need admin right, from a C# app launch from user space. Of course, the complication, that's I don't want the UAC.

I want to run an action like this:

PsExec.exe -i -s powershell.exe -command "whoami *> 'out.txt'"
  • If I run example in cmd/powershell with admin right, it's work.
  • If I run example in C# exe with process with verb = "runas", it's working
  • If I run example in C# exe with process with user/password/domain, it's not working

I've tried a lot of other things, but I've not find a good trick. (powershell with credential, run a .bat or .ps1, ...)

I'm open to every solution and/or if it's really doable.

stuckoverflow
  • 625
  • 2
  • 7
  • 23
  • Why use `psexec` at all? What are you trying to do? You can create and execute a Powershell pipeline in code, you don't need `psexec` or `Process.Start`. On the other hand, you *can't* just bypass the UAC warning. If it was that easy, it would be useless as a security measure – Panagiotis Kanavos Feb 19 '21 at 12:43
  • This sounds like an [XY problem](https://xyproblem.info). What problem are you trying to solve? – Bill_Stewart Feb 19 '21 at 12:55

1 Answers1

0

You cannot do this. Windows is a secure operating system, and you need to be an administrator to perform administrator tasks.

Pretend for a moment that UAC doesn't exist.

  • pretend that we're back on Windows XP
  • you are a standard user
  • and you want to use PsExec to run something as the System account

You cannot. A standard user is not allowed to compromise the security of the system like that.

The only way you can do that is to run as an Administrator.

  • On Windows XP, you would have to logoff, and get an administrator to login for you

Windows Vista, and UAC, made it easier than having to completely switch to another user:

  • you can just enter their credentials in the UAC dialog (or press Continue)

But you cannot just arbitrarily elevate yourself to an administrator - that defeats the entire purpose of having a secure operating system.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219