views:

1900

answers:

3

I am developing an application using vb.net. For performing some tasks the application needs administrator privileges in the machine. How to ask for the privileges during the execution of the program?

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

+1  A: 

There are several articles on the Internet about developing elevated processes in Vista, but essentially elevation requests involve decorating .NET assemblies and WIN32 executables with elevation status in the application manifest file (may be embedded or side-by-side).

There is an excellent blog post about your question which provides the code you'll probably need:

.NET Wrapper for COM Elevation

splattne
A: 

I have not done this yet but I believe you go to (in VS 2008) Project Settings -> Application Tab and click on the "View UAC Settings" button. This opens up your app.manifest file. In there is a tag which I think holds the options you're looking for. Mine has some options commented out which should get you started:

Bryan Anderson
A: 

You can edit the UAC Settings (in VB 2008) which is located in the Project Settings. Look for the line that says

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

Change level="asInvoker" to

  1. level="asInvoker" (normal account)
  2. level="requireAdministrator (require administrator)
  3. level="highestAvailable" (if anything is higher then administrator, require that)

3e0! Website