Search code examples
c#wpfservicevisual-studio-2013elevated-privileges

How to force my project in Visual Studio 2013 to always run as Administrator?


I have a WPF project in Visual Studio 2013, this project have two buttons. The first button say Start Service and the second say Stop Service. When I run my Visual Studio as Administrator, the buttons work. But when I open my Visual Studio without privilages, the InvalidOperationException exception appear.

How to force my project start with privilages when Visual Studio doesn't run as administrator?

I added app.manifest to my project and change for

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

but it didn't function.

For start or stop my service, I am using ServiceController.


Solution

  • This is interesting and it seems you need to change permissions of how the project runs, Try doing the following

    • go to project properties > Security
    • enable click-once security settings and select Full trust application

    More infor in this link WPF security