3

Possible Duplicate:
How to prevent Vista from requiring elevation on patch.exe?

One of my programs is called "PatchCompiler.exe". It runs in the console. Or rather, it doesn't run, because Windows 7 treats an EXE file differently if it has "Patch" anywhere in its name, requiring elevated permission ("Do you want to allow the following program from an unknown publisher to make changes to this computer?"). Even if I grant this permission, it runs in an ephemeral console that disappears before I can see its output.

Yes, I know I could fix this problem by renaming my program. But it compiles patches...

Does anybody know how to change this annoying behaviour?

Edited to add: Just to make myself clear: I don't want my program to run with elevated status! Who knows what bugs I left in it?

Community
  • 1
  • 1
  • I was having a similar problem with a program called "DynamicDispatchTest.exe". Not that big a deal since it's obviously (from the name) just a quick program I created to test something, but I never would have guessed that the filename of all things was the culprit! – flarn2006 Nov 06 '14 at 01:35

3 Answers3

5

Attach an application manifest that includes

<requestedExecutionLevel level="asInvoker" uiAccess="true"/>
phihag
  • 278,196
  • 72
  • 453
  • 469
  • How do I do that with g++ under MinGW? – TonyK Oct 27 '11 at 10:33
  • @TonyK See http://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/ for a detailed explanation. – phihag Oct 27 '11 at 10:40
  • That worked (after a little massaging). Thank you! I have put the details into a new answer. (I would accept your answer, but I originally posted this on superuser.com as another `TonyK`...) – TonyK Oct 27 '11 at 11:25
  • contact a mod, and get them to merge the users. – Journeyman Geek Oct 27 '11 at 12:56
  • @TonyK: Sorry, I can't merge an account that doesn't exist. You have to log into SU and SO with the same credentials for the migration of a question to retain your identity. –  Oct 27 '11 at 13:35
2

OK, I got it working, thanks to phihag's answer. It didn't work straight from the box, so here's what I did:

  1. Create a file Manifest.xml:

    <?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.v2">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
          </requestedPrivileges>
        </security>
      </trustInfo>
    </assembly>
    
  2. Create a resource file, Manifest.rc:

    #include "winuser.h"
    CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST Manifest.xml
    
  3. Compile the resource file to create Manifest.res:

    windres --input Manifest.rc --output Manifest.res --output-format=coff
    
  4. Add Manifest.res to the link:

    g++ -Wall -oPatchCompiler PatchCompiler.cpp Manifest.res
    

And that's it!

TonyK
  • 16,761
  • 4
  • 37
  • 72
-1

As far as I know, that's a feature, not a bug. The idea is to make sure that you really really want to run a patch on your computer.

Also, as far as I know, there isn't a nice way to solve the problem. You could disable the UAC or rename the program.

As far as the console is concerned, that's a programming question and there's not enough information to help you. You should simply add a check which will wait until you do something before closing the program. A typical example of that is reading a character from terminal at the end.

You could start an elevated command prompt which shouldn't bring the UAC warning when starting the program and should stay on after the program is completed.

AndrejaKo
  • 1,721
  • 5
  • 25
  • 41
  • 4
    Feature or Bug ... Trust Windows to base a file's contents on the NAME, giving rise to the FUN.JPG.EXE viruses... Magic Numbers for the win! This weird thing with Windows means that I can take a GOOD program and make it seem evil by simply renaming it... and conversely, make an evil patcher program good in the same manner. Good Job MicroSoft. You'd think it would be better to determine privileges based on what a program DOES... if it opens an .exe/.dll for read/write versus exec... THAT'S a problem needing elevated privs. – lornix Oct 27 '11 at 09:47
  • 2
    It's a bug; the name of a file has nothing to do with what the file *is*. – David X Oct 27 '11 at 10:04
  • @David X It's a feature according to [this](http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/bf4f7dfa-5553-41d3-9c8e-311ee4a88599/). I won't comment on how smart it is. Also there's [this](http://technet.microsoft.com/en-us/library/cc709628%28WS.10%29.aspx) under `Installer Detection Technology` – AndrejaKo Oct 27 '11 at 10:15
  • An operating system that bases its behaviour on whether the character sequence "patch" occurs in the name of an executable file? Really, only morons could have designed that. It's such a stupid feature that it's a bug. – TonyK Oct 28 '11 at 17:15
  • **It's a feature whose existence is a bug.** All happy? ;) A proper implementation of a design based on an idea that is massively flawed in that it fails to offer actual protection. AND violates the requirement of not being too inconvenient in legitimate uses. – kaay May 31 '23 at 12:29