3 Replies - 844 Views - Last Post: 07 April 2017 - 08:40 AM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Arg for ShellExecute() Equivalent to Runas Admin?

Posted 06 April 2017 - 10:16 AM

Y helo thar DICers,
Does anyone know, for the ShellExecute() command if there is an arg to run as admin? I've been fighting with PS for weeks and I just need C++ to run that command as if you right clicked on a file and did "runas admin."

If you can help me love you long time :beta1:
Is This A Good Question/Topic? 0
  • +

Replies To: Arg for ShellExecute() Equivalent to Runas Admin?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5897
  • View blog
  • Posts: 20,136
  • Joined: 05-May 12

Re: Arg for ShellExecute() Equivalent to Runas Admin?

Posted 06 April 2017 - 10:44 AM

As I recall, there is a trick, but there is a more secure way to go about this:

You can mark your application as needing elevation to run as admin. Any processes that you spawn off will inherit the elevated permissions. You do this by adding an application manifest to your program. You can have the linker do this for you by using the -ManifestUAC flag, or you can manually link in your own manifest file.

You don't want Joe Random user to run across your program, swap in their own PowerShell script and just run your program to get their script to run elevated. The will have to be able to run your program elevated first.
Was This Post Helpful? 1
  • +
  • -

#3 Sam Hobbs  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 50
  • Joined: 01-April 17

Re: Arg for ShellExecute() Equivalent to Runas Admin?

Posted 06 April 2017 - 12:57 PM

See .net - How to start a Process as administrator mode in C# - Stack Overflow and posts linked from it and Start Process with administrator right in C# - Stack Overflow. Note that there is an "Advanced" button in the properties of shortcuts and we can specify Administrator privileges for the command there, in case that helps.
Was This Post Helpful? 1
  • +
  • -

#4 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: Arg for ShellExecute() Equivalent to Runas Admin?

Posted 07 April 2017 - 08:40 AM

SKYDIVER!!!!!! EYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY YOURETHEMANNOWDOG.COM!!!!!!!!!!! THANK YOU!!!

WORKED FLAWLESSLY.

So all I had to do was do what you said... mess wwith the linker add that in and then add:
Set-Executionpolicy unrestricted
to the beginning of the script.

seriously... you made my day man. Can't say thanks enough. :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1