Bill Greer
Bill Greer

Reputation: 3156

How do I require my Visual Studio published application to run as administrator?

Is there an option in the application properties ? I cannot find anything that tells Visual Studio that my application will need to be run in an elevated state.

Upvotes: 0

Views: 606

Answers (1)

vapcguy
vapcguy

Reputation: 7537

If you're just trying to do this on your development machine, you could:

Log in as the Administrator and run Visual Studio -OR- Right-click the Visual Studio shortcut and click "Run As" and supply the Administrator account credentials.

If this is for an application you are developing to live on a server where the server cannot be left logged in as an Administrator while your application runs, you should either:

  • Build in impersonation into the code of the application, so it will run as whatever account you want it to run under
  • Give that account Administrator privileges (if allowed) or choose an account that already has the desired privileges for the WindowsImpersonationContext.

Info on Impersonation:

Without information about your app, i.e. if it is a web app or standard exe or SharePoint web page, it's hard to give you more specific info. For .NET web apps, ensure you use Windows authentication and set your app pool to run under the account with Admin privileges. Note that you may still need to add the Impersonation code into your app where you need the higher privileges, even if it is running under that account.

For SP pages, you need SPSecurity.RunWithElevatedPrivileges(function(){ ... });

Upvotes: 1

Related Questions