Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UAC need for console application

I have a console application that require to use some code that need administrator level. I have read that I need to add a Manifest file myprogram.exe.manifest that look like that :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">     <security>       <requestedPrivileges>         <requestedExecutionLevel level="requireAdministrator">       </requestedPrivileges>     </security>   </trustInfo> </assembly> 

But it still doesn't raise the UAC (in the console or in debugging in VS). How can I solve this issue?

Update

I am able to make it work if I run the solution in Administrator or when I run the /bin/*.exe in Administrator. I am still wondering if it's possible to have something that will pop when the application start instead of explicitly right click>Run as Administrator?

like image 445
Patrick Desjardins Avatar asked Oct 22 '08 19:10

Patrick Desjardins


People also ask

Why do we need console application?

A console application is primarily designed for the following reasons: To provide a simple user interface for applications requiring little or no user interaction, such as samples for learning C# language features and command-line utility programs.

Is console application easy to develop?

Simplicity. Creating a console application is more straightforward than building an application that has a rich user interface. You do not need to know or use any user interface languages, tools or frameworks. You can implement a console application using simple C# programming.


1 Answers

For anyone using Visual Studio, it's super easy. I was about to go set up the Windows SDK and do mt.exe post-build steps and all that before realizing it's built into VS. I figured I'd record it for posterity.

  1. Project | Add New Item -> Visual C# Items -> Application Manifest File
  2. Open app.manifest, change requestedExecutionLevel.@level to "requireAdministrator"
  3. Build

Ta-da

like image 161
scobi Avatar answered Sep 20 '22 06:09

scobi