How can I force my .NET application to run as administrator in C#?
How can I force my .NET application to run as administrator in C#?
21812-Jul-2023
Updated on 13-Jul-2023
Home / DeveloperSection / Forums / How can I force my .NET application to run as administrator in C#?
How can I force my .NET application to run as administrator in C#?
Aryan Kumar
13-Jul-2023Sure, there are two ways to force your .NET application to run as administrator in C#:
1. Modify the application manifest
The application manifest is a file that contains information about the application, such as its name, version, and requested execution level. You can modify the application manifest to force the application to run as administrator by changing the
requestedExecutionLevel
value torequireAdministrator
.To do this, open the application manifest file in a text editor and change the
requestedExecutionLevel
value torequireAdministrator
. For example, the following code shows how to modify the application manifest to force the application to run as administrator:XML
Once you have modified the application manifest, you will need to rebuild the application. After the application has been rebuilt, it will always run as administrator, regardless of the user account that is used to run the application.
2. Create a shortcut with the "Run as administrator" option
You can also force your .NET application to run as administrator by creating a shortcut with the "Run as administrator" option. To do this, right-click on the application shortcut and select "Properties". In the "Shortcut" tab, click on the "Advanced" button and check the "Run as administrator" checkbox.
Once you have checked the "Run as administrator" checkbox, the shortcut will always run the application as administrator, regardless of the user account that is used to run the shortcut.