Search code examples
c#adminuac

How to make a program Run as Administrator Automatically


I am currently coding a WPF project. The project is a sort of Task Manager program. Inside of the project, there are methods that take real-time PC data (temp, frequency, etc). However, some of the methods in the project require administrator privileges, so that the program can have access to the different values/data from the PC.

The problem at hand is that the program asks for these permissions every time the program is run. While I know this is just a personal preference, I would like to make the program only ask for the said privileges at installation/first run, so that the user does not have to authorize their permission every time.

Just to be clear, this is not a question about how to get the administrator privileges in general. I know that there is the option to manipulate the app.manifest file. This question is only pertaining to keeping the set administrator privileges programmatically, or through other means such as visual studios.

(Also, the program uses NSIS as an installer, if this is at all helpful)

Thanks

EDIT:

Looking back at this question, it was a pretty stupid one. It was just due to my sloppy/lazy coding.


Solution

  • That is not possible because the purpose of UAC Prompt is to create awareness for the user so they know that they are allowing admin privileges to the software.

    I Do not really advise you to skip the step of the prompts.

    You can not do it directly but you can indirectly , if you can write a code to do the following steps here , you can achieve what you asked for.