问题
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?
回答1:
Attach an application manifest that includes
<requestedExecutionLevel level="asInvoker" uiAccess="true"/>
回答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:
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>
Create a resource file,
Manifest.rc
:#include "winuser.h" CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST Manifest.xml
Compile the resource file to create
Manifest.res
:windres --input Manifest.rc --output Manifest.res --output-format=coff
Add
Manifest.res
to the link:g++ -Wall -oPatchCompiler PatchCompiler.cpp Manifest.res
And that's it!
回答3:
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.
来源:https://stackoverflow.com/questions/7914180/windows-7-exe-filename-starts-with-patch-wont-run