C# - Run application as administrator automatically

In this tutorial, you will learn how you can run your application as administrator automatically using Visual C#2010.

Start by opening your C# Windows forms application.

Right click on your project name in the solution explorer and add a new item...

Select an application manifest file:

Click add.

A new tab should open up, most of the codes in it are not important to us.
There is one line however that we need to change (marked in blue):

Change asInvoker to requireAdministrator.

Save your application and rebuild it.

Take a look at the icon of your executable file:

 It has an admin shield in front of it !

You can only open your executable when using Administrator rights.

If you have any more questions, please leave them in the comment section below.

Have a nice day !


Topic: C# - Run application as administrator automatically

Date: 24/11/2013

By: sadegh

Subject: help

hi
in VS 2013 dosn't work!
why?

Reply

—————

Date: 03/05/2013

By: shiwa

Subject: run an application automatically

I need my application run automatically from a flash disk

Reply

—————

Date: 03/04/2013

By: Narendra

Subject: run as Administrator

This is very useful ...

Reply

—————

Date: 09/11/2012

By: Lahiru

Subject: run as Administrator

his works fine in vs 2012 also.thank you very much for this post.

tmsrlahiru@gmail.com

Reply

—————