Windows vista / 7 / server 2008 R2 uses User Account Control (UAC) technology to protect and protect the OS from malware, limiting application privileges to administrator permission. It is for this reason that we need to make our application work as an administrator. This is usually done when the application starts. This process, right-click on the application and click "Run as administrator" to start the application with administrator rights. If we assume that the user forgot to do this and starts the application normally, then unexpected behavior may be observed. Since all actions requiring administrative privileges in win vista and higher (for example, calling a process, using the system disk, etc.) will not be performed.
To avoid running the application as an administrator each time, we can make our application run as the default administrator. To achieve this, we need to adjust a bit with the application manifest. An application phenomenon is an XML file that describes an application.
Follow these steps to get your .net application running as an administrator:
Step 1: go to the project properties and click the "View Windows Settings" button. This will open the file "app.manifest".
Step 2: In the requested “ExecutionLevel” key, change the value of the “requireAdministrator” level and the uiAccess value to “False”. A configuration level of "requireAdministrator" means that the application runs only for administrators and requires that the application be run using an administrator access token. Setting uiAccess as "False" means that the application does not need to enter input into the user interface of another window on the desktop. Applications that do not provide accessibility should set this flag to false. Applications that are required to enter input into other windows on the desktop (for example, on-screen keyboard) must be true.
Step 3. Save the changes, rebuild the application and install it in Win Vista or higher.
Now the application will start automatically as an administrator.
Harsh
source share