简体   繁体   中英

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.

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.

Windows is a secure operating system. If the user is not an administrator: then you don't get to control that.

What would your application have done under Windows XP?

  • Would it have crashed?
  • Would you have refused to run?
  • Would you have told the user that they need to be an administator?

Is there no lesser mode you can use that can still give the user useful information? After all, Process Explorer is still able to run and give me all kinds of useful information about processes on the computer.

But if the user is a standard user, you have no way to change that at install time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM