Search code examples
c#admin

How to remove the "Run as Administrator" requirement in C#


I have a program that uses the registry to save the last 10 files that have been opened. At one time I was trying to save them in local machine, but instead decided to save them in the current user. During the course of trying to get everything to work I created a manifest to force the program to Run As Administrator, which I don't beleive is required any more. The problem I'm having is I can't seem to remove the requirement.

I have.... Changed the project properties to "Create application without a manifest", Added a new item called app.manifest which defaults to asInvoker and changed the properties to use that manifest, renamed any file that has the word manifest in the file name.

None of these attempts worked. The program still is running as an administrator. I must be missing something but I'm not sure what.

Here are the lines in the app.manifest

  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
  </requestedPrivileges>

Thanks for the help!!

Gary


Solution

  • Take a look at the app.manifest file in the Properties folder. Remove the following line:

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

    Add the following line instead of this:

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

    If this did not help, first make sure that you also removed the manifest file from the bin\Debug folder. Simply removing it from the solution does not help, because the file might still be available in the output folder.

    That's why I think you should not remove the manifest file from the project, but change it that it works as expected.