3

Is there a way I can add a setting in the configuration file so that that application will always start as admin? Thanks a lot.

Andrea Nagar
  • 1,233
  • 2
  • 13
  • 23

1 Answers1

5

Not from the config file, but in the .manifest.

<?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" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

http://blogs.msdn.com/b/nikhiln/archive/2007/04/19/embed-a-manifest-to-make-an-application-elevate-in-vista.aspx

Mark Sowul
  • 10,244
  • 1
  • 45
  • 51
  • Thanks so much. That works great. I added a manifest file to visual studio but now the application always requires admin privileges when it starts, even if I remove the manifest file from the installation folder. How can I make the application start as admin only if the manifest file is present in the folder? – Andrea Nagar Feb 11 '13 at 09:28
  • Not sure if it's cached or something. You have a mainfest alongside the .exe, not embedded, right? – Mark Sowul Feb 13 '13 at 20:00
  • Thanks for your reply Mark. What I did was just copying the manifest in the same folder I put the exe file. I'm not sure if that's the proper way to do it. The file was named myfile.exe.manifest – Andrea Nagar Feb 14 '13 at 09:11
  • That's how it should work; I'm surprised that removing it would still result in UAC requests. I tried finding any documentation on whether Windows caches this, but couldn't find any. – Mark Sowul Feb 14 '13 at 20:06
  • Thanks. My problem is that when I copy the file in the installation folder, the application still runs as non admin. I'll probably create a second executable that automatically runs as admin. – Andrea Nagar Feb 14 '13 at 23:26
  • Manifests can be embedded. Starting from Windows Vista, embedded manifests have precedence over external manifests, i.e. a separate manifest file (see https://stackoverflow.com/questions/17853304/manifest-embedded-and-external-which-has-priority-can-one-override-other). – riQQ Mar 09 '20 at 15:04