Share via


C# Start program in administration rights

Question

Monday, November 8, 2010 8:28 PM

Hello,

I am writing my application in C#. And I need to run the program as administaror because the program need to move files.

How gonna i do so that when user clicks on it it opens as administrator?

All replies (4)

Tuesday, November 9, 2010 6:41 AM ✅Answered | 1 vote

This may help:

http://www.enusbaum.com/blog/2007/08/26/how-to-run-your-c-application-as-administrator-in-windows-vista/


Tuesday, November 9, 2010 7:03 AM ✅Answered | 1 vote

http://msdn.microsoft.com/en-us/library/bb756929.aspx

 

http://msdn.microsoft.com/en-us/library/dd371711(VS.85).aspx

 

 

Knowledge is like light; It spreads only when you have clear and transparent mind.


Tuesday, November 9, 2010 7:54 AM ✅Answered

Hello Chechen18,

   Kindly, add the below code in your app.manifest file located in the Properties folder in your project in Solution Explorer:

 <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
 <security>
 <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
 <!-- UAC Manifest Options
  If you want to change the Windows User Account Control level replace the 
  requestedExecutionLevel node with one of the following.

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

  If you want to utilize File and Registry Virtualization for backward 
  compatibility then delete the requestedExecutionLevel node.
 -->
 <requestedExecutionLevel level="asInvoker" uiAccess="false" />
 </requestedPrivileges>
 <applicationRequestMinimum>
 <defaultAssemblyRequest permissionSetReference="Custom" />
 <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
 </applicationRequestMinimum>
 </security>
 </trustInfo>
</asmv1:assembly>

NOTE: All the files and folders in the Program Files will need the Administrator Rights in order to access and execute.

For creating shortcut, you need to create Setup Project. Please find the link for the same:

http://parassanghani.blogspot.com/2010/08/how-to-create-setup-project-in-vs-2008.html 

Thanks,

Paras Sanghani

http://parassanghani.blogspot.com/

Mark As Answer if it helped you.


Thursday, November 11, 2010 8:37 AM

Hi  Chechen18,

Welcome to MSDN Forums!

 

If your question has been solved, please don’t forget mark/vote the replies which helped you, and this will encourage the other community members to join in discussion and help each one.

 

Best wishes,

Mike

*****************************************************

[All-In-One Code Framework]

Sample world! You will get more from this world!

Welcome to the new world!