How To Force/Prompt Your C# & VB.NET Program To Run As Administrator

If your code will target or access secured files or libraries, then your program needs Administrator Privilege. It's easy to run your program as Administrator, simply you can right click your program and select run as administrator, and in C# & VB.NET theres a XML Manifest that tells the .NET Framework to prompt the user to run the program as Administrator, we can easily configure your program to prompt the user to run the program as administrator.

How to configure your program to prompt the user to run your program as Administrator?

1 : Go to Project(in your visual studio menustrip) and select Add New Item(or simply CTRL+SHIFT+A shortcut to open Add New Item)

outling





















2 : Choose Application Manifest File and click add(actually your debug folder has a manifest file but we are adding a new one)
man

























3 : You will find a new file in your Solution Explorer called app.manifest and you will fall into that file automatically lol, inside that file you would have some text(of course XML)

  
  
    
      
        
        
      
    
  

  
    
      

      
      

      
      

      
      

    
  

  
  


4 : Inside that file find  <requestedExecutionLevel level="asInvoker" uiAccess="false" />

5 : Replace asInvoker with requireAdministrator

6 : That's all

Now whenever you run your program, your program will prompt to run the program as Administrator.

6 comments

but ClickOnce does not support the request execution level 'requireAdministrator'

Reply

same problem here
so Shim any solutions for this problem?

Reply

try this http://social.msdn.microsoft.com/Forums/vstudio/en-US/abd9d2b5-dca1-45c5-8636-e2f0ce963986/clickonce-does-not-support-the-request-execution-level-requireadministrator?forum=vbgeneral

Reply

try this http://social.msdn.microsoft.com/Forums/vstudio/en-US/abd9d2b5-dca1-45c5-8636-e2f0ce963986/clickonce-does-not-support-the-request-execution-level-requireadministrator?forum=vbgeneral

Reply

Hmm, your example doesn't work, but I added a new app.manifest from menu and after change asInvoker to requireAdministrator it works :)

Reply

Post a Comment

Note: Only a member of this blog may post a comment.