This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16352|Reply: 0

[WinForm] How to run a program as an administrator in C#

[Copy link]
Posted on 2/19/2016 3:07:41 PM | | | |
When using the winform program to obtain the cmd command prompt, if it is an operating system above win7, it will need to be run as an administrator to execute successfully, otherwise there will be no effect or error prompt.
     For example, when executing the cmd command through the winform program, in some cases, if you are not running as an administrator, the command will be invalid.
     Or when executing a Windows Service service through the winform program, you also need to call the Service service as an administrator.
Here's how to make the program run with administrator rights.
One: In Visual Studio - Solution Explorer - Right click on the project name - Properties, find the "Security" option,
2: Check "Enable ClickOnce security settings",
Three: At this time, there will be an additional "app.manifest" file under the project, select it, find the code snippet, and change it to: ,
Open it:
Modified the above diagram to read:
Four: After correction, do not rush to recompile and generate, open the "Properties - Security" interface again,
Remove the checkmark in front of "Enable ClickOnce security settings" before compiling and running. Otherwise, the program will report an error and cannot run.

5: Finally, save the modifications and recompile the running program.
When you open the program, you will be prompted to "User Account Control" to get administrator privileges to run, and click "Yes" to obtain admin rights.





Previous:C# text boxes clear spaces, line breaks, etc
Next:php generates random numbers
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com