Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to distribute a program to windows (XP, 7, 8) users. The program requires administrative rights because it adds and removes routes, among other things. The problem is that the "Run this program as administrator" flag on the executable is not preserved, so I figure I could programmatically add this using a batch script or something similar in a sort of setup script.

Is this the right approach, and if so how does one add this flag?

share|improve this question
2  
AFAIR you have to embed a manifest file in your executable. –  gronostaj Aug 5 '13 at 9:33
    
So if such a manifest file specifically states that the executable should carry this flag/option, it will be inherited when I copy the executable to another system? –  user135361 Aug 5 '13 at 9:55
    
@gronostaj: Embedding is allowed, but not necessary. You can also have it in a side file (app.exe.manifest). But yes, this is a major pain. A sane OS designer would have added this flag where all the other similar flags are (in the PE header), but not Microsoft. –  MSalters Aug 5 '13 at 10:02
    
@user135361 Yes. See my answer below for an example. –  gronostaj Aug 5 '13 at 10:03
add comment

1 Answer

up vote 5 down vote accepted

You can include a manifest file in executable's resources. It will make Windows require Administrator privileges for that file on all systems.

You can open any installer with Resource Hacker and you'll find an XML file like this one:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
    <ms_asmv2:security>
      <ms_asmv2:requestedPrivileges>
        <ms_asmv2:requestedExecutionLevel level="requireAdministrator" uiAccess="false"></ms_asmv2:requestedExecutionLevel>
      </ms_asmv2:requestedPrivileges>
    </ms_asmv2:security>
  </ms_asmv2:trustInfo>
</assembly>

That's the manifest file. You need something like this compiled into resources.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.