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

12

我正在Ubuntu下使用i586-mingw32msvc进行交叉编译应用。

我不太清楚如何在mingw32中嵌入一个需要管理员权限的manifest文件。

这是我使用的示例hello.c

int main() {
    return 0;
}

这个资源文件 hello.rc

1 Manifest "hello.exe.manifest"

这个清单文件 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>

我使用以下命令编译资源文件:

i586-mingw32msvc-windres hello.rc hello.o

我使用以下内容编译我的最终应用程序:

i586-mingw32msvc-gcc -O3 -Os -s -o hello.exe hello.c hello.o

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

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

我错过了什么?

EDIT1: 使用Resource Hacker尝试修改由NSIS创建的Setup.exe文件后,唯一敏感的区别是在我的hello.exe中写成MANIFEST,而在Setup.exe中则是Manifest。尽管在hello.rc中它被写为Manifest. O_o

NSIS Installer vs hello.exe

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

Modified with Resource Hacker

现在hello.exe正常工作,触发UAC警报并以管理员身份运行。看起来像是i586-mingw32msvc-windres中的一个“错误”。 :-)


这可能会有所帮助:http://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/ - Jonathon Reinhart
@JonathonReinhart 谢谢你,但我已经尝试了链接中描述的方法,以及链接到的链接 https://msdn.microsoft.com/en-us/library/bb756973.aspx。但是没有任何改变。我已将我的 hello.rc 文件更新为 1 Manifest "hello.exe.manifest"。使用 Resource Hacker,我打开了一个需要管理员权限的 NSIS 安装程序(我使用 makensis 编译),一切都基本相同;唯一不同的是,在 Setup.exe 文件中,清单字段写作“Manifest”,而在我的 hello.exe 文件中写作“MANIFEST”!(请参见此处 http://i.imgur.com/WzHtXnw.png) - pr.nizar
通常你要编译 .rc 文件生成 .res 文件,而不是 .o 文件。 - M.M
请帮我,imgur的图片在哪里? - Ahmed Can Unbay
2个回答

8

关于神奇的数字1和24:

1 24 "hello.exe.manifest"

那行代码的翻译大致如下:
ID_MANIFEST RT_MANIFEST "hello.exe.manifest"

定义如下:

这些宏定义的含义如下:

#define ID_MANIFEST 1
#ifndef RT_MANIFEST
#define RT_MANIFEST MAKEINTRESOURCE(24)
#endif

如上所示,通过条件包装器,RT_MANIFEST可能已经被定义,如果你在谷歌搜索该术语RT_MANIFEST,你会发现有很多相关的细节信息。


3

通过一些强大的技巧,我在我的hello.rc文件中使其正常工作:

1 24 "hello.exe.manifest"

不会搜索以了解24是什么(资源类型清单?!).. :-)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接