Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win C#: Run app as administrator without UAC prompt

Tags:

c#

.net

windows

uac

I need one of my .exe to always run as administrator without UAC prompt. My program will be installed with setup, which will have for one time admin rights, and I need to perform such step in this setup that my exe will be always executed as admin without UAC prompt.

I've found 2 solutions so far:

1. Use custom service, which will elevate the program for me.

2. Use Task Scheduler.

Is there any other solution? Some manifest probably?

Thanks.

like image 205
Paya Avatar asked Mar 21 '10 20:03

Paya


People also ask

What is Win C?

The Windows key (Windows key + Q does the same thing.) Windows key + C: Open Cortana in listening mode (similar to saying "Hey, Cortana"). Windows key + E: Open File Explorer. Windows key + F: Open the Windows 10 Feedback Hub.

What is Ctrl C used for?

Keyboard Command: Control (Ctrl) + C The COPY command is used for just that - it copies the text or image you have selected and stores is on your virtual clipboard, until it is overwritten by the next "cut" or "copy" command.


2 Answers

If it were possible to do this, then UAC would be completely ineffective. The inability of applications to elevate themselves without user consent is the fundamental principle behind UAC.

Aside from already having an elevated process that launches it (i.e. service or task scheduler), the answer is no, it can't be done.

like image 137
Aaronaught Avatar answered Sep 26 '22 05:09

Aaronaught


Of course what you are supposed to do if you want to just drive UI is to use the UI access flag in your manifest (see http://msdn.microsoft.com/en-us/library/ms742884.aspx). If you install your application in a trusted location (e.g. system32) and it is signed (bleh!) then when you run your application it will be elevated to high (for an admin account).

The signing requirement makes it slightly annoying but at least it reduces slightly the attack surface as your code gets run with high integrity but not with an administrator token.

like image 24
tyranid Avatar answered Sep 23 '22 05:09

tyranid