24

I have a WPF application that I want to make it able to start always as an Adminstrator. I've been reading a lot about it and it seems that I have to create my own manifest file and pass it to the Application properties so that on runtime it starts as an Administrator.

The application itself loads a file and sometimes the file might demand administrator access so it can be modified. That is why I am looking for a way after the Application gets installed to be able to always get started in administrator mode.

Pang
  • 9,564
  • 146
  • 81
  • 122
mathinvalidnik
  • 1,566
  • 10
  • 35
  • 57
  • 1
    To create the manfiest, right-click your project, select Add new item..., and choose the Application Manifest type. – dlev Jul 01 '13 at 14:23

2 Answers2

52

To add a Manifest, right click on your project file in Solution Explorer:

  1. Select Add

  2. New item

  3. Choose Application Manifest File

The file should be named app.manifest. Don't rename it.


You have to change the <requestedExecutionLevel> element in your Manifest to start always as an Adminstrator:

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

BTW: A good article for this question:
https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-security-overview

Pang
  • 9,564
  • 146
  • 81
  • 122
  • You can't do it when publishing with ClickOnce. – Ricardo França Jul 08 '16 at 12:22
  • Why not? According to MSDN it's the same XML specification: https://msdn.microsoft.com/en-us/library/ws1c2fch.aspx – Smartis has left SO again Jul 08 '16 at 12:32
  • Well, I added the manifest file, changed the line you told and try to publish a ClickOnce version. The result is an error: "ClickOnce does not support the request execution level 'requireAdministrator''. – Ricardo França Jul 08 '16 at 12:41
  • To start as admin I did a workaround that starts a new process as Admin and kill the current wich is not admin. More details: http://stackoverflow.com/questions/2532769/how-to-start-a-process-as-administrator-mode-in-c-sharp – Ricardo França Jul 08 '16 at 12:46
2

In Visual Basic, the project properties are structured a little differently. If you find this question and you're in VB in VS2010, follow these instructions to generate an app.manifest file.

  1. To create an app.manifest file, go to your project, and select properties. Then click on View Window Settings, under the Application tab.
    • ViewWindowSettings
  2. This should generate and open the app.manifest file, which is saved in your My Project Folder
    • app.manifest

Further Reading: WPF MessageBox window style

Community
  • 1
  • 1
KyleMit
  • 30,350
  • 66
  • 462
  • 664