使用mingw32嵌入清单文件以要求管理员执行级别

pr.*_*zar 8 c linux windows uac mingw32

我正在ubuntu下用i586-mingw32msvc交叉编译一个应用程序.

我很难理解如何嵌入清单文件以使用mingw32要求管理员执行级别.

对于我的例子,我使用了这个hello.c:

int main() {
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个资源文件hello.rc:

1 Manifest "hello.exe.manifest"
Run Code Online (Sandbox Code Playgroud)

这个清单文件hello.exe.manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="hello" type="win32"/> 
    <description>Hello World</description> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>
Run Code Online (Sandbox Code Playgroud)

我编译我的资源文件:

i586-mingw32msvc-windres hello.rc hello.o
Run Code Online (Sandbox Code Playgroud)

我编译我的最终申请:

i586-mingw32msvc-gcc -O3 -Os -s -o hello.exe hello.c hello.o
Run Code Online (Sandbox Code Playgroud)

SigCheck不显示正在运行的清单文件sigcheck -m hello.exe.

现在,当我在Windows下运行我的应用程序时,它不会触发UAC(=不以管理员身份运行),而当我将hello.exe.manifest文件附加到同一文件夹时,它会触发UAC(如预期的那样).

我错过了什么?

EDIT1:摆弄资源黑客我已经开了Setup.exe,我用NSIS创建的文件,唯一明智的区别是,ManifestMANIFEST在我hello.exeManifestSetup.exe尽管hello.rc它的书面清单.O_O

NSIS安装程序vs hello.exe

EDIT2:我已经Manifest使用Resource Hacker手动更改了组:

使用Resource Hacker修改

现在hello.exe通常会触发UAC警报并以管理员身份运行.看起来像是一个"虫子" i586-mingw32msvc-windres.:-)

jus*_*sij 8

关于魔法巫术数字 1 和 24:

1 24 "hello.exe.manifest"
Run Code Online (Sandbox Code Playgroud)

该行翻译成这样:

ID_MANIFEST RT_MANIFEST "hello.exe.manifest"
Run Code Online (Sandbox Code Playgroud)

其中这些定义定义如下:

#define ID_MANIFEST 1
#ifndef RT_MANIFEST
#define RT_MANIFEST MAKEINTRESOURCE(24)
#endif
Run Code Online (Sandbox Code Playgroud)

如上面的条件包装器所示,RT_MANIFEST可能已经被定义,如果您在 Google 中搜索该RT_MANIFEST术语,您会发现大量命中内容,其中包含有关正在发生的情况的更多详细信息。