How does the program request administrator rights?

I am developing an application using vb.net. To perform some tasks, the application needs administrator privileges on the machine. How to request privileges at runtime?

What is the general method of switching user accounts to run an application? In other words, is there a way to run the application under an arbitrary user account?

+6
privileges
source share
4 answers

You can edit the UAC Settings (in VB 2008), which is located in the project settings. Find the line that says

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

Change level = "asInvoker" to

  • level="asInvoker" (same access token as the parent process)
  • level="requireAdministrator (requires full administrator)
  • level="highestAvailable" (the highest privileges available to the current user)
+4
source share

There are several articles on the Internet about developing elevated processes in Vista, but mostly elevation requests include decorating .NET collections and WIN32 executables with elevation status in the application manifest file (can be embedded or side by side).

There is a great blog post about your question, which contains the code you are likely to need:

.NET Wrapper for COM Elevation

+3
source share

I have not done this yet, but I believe that you go to (in VS 2008) the project settings → the "Application" tab and click on the "View UAC Settings" button. This will open the app.manifest file. There is a tag in the tag, which I think contains the options you are looking for. Mine has some options you should have started:

+3
source share

In VS 2015: Go to: Project → (project name) Properties ... → Application → Browse through Windows settings and find in app.manifest (line 19): And change asInvoker to:

  • "asInvoker" (same access token as the parent process)
  • "requireAdministrator (requires full administrator)
  • "highAvailable" (highest privileges available to the current user)
+1
source share

All Articles