[英]Embed manifest file to require administrator execution level with mingw32
我正在用ubuntu下的i586-mingw32msvc交叉編譯應用程序。
我在理解如何嵌入清單文件以要求管理員使用mingw32執行級別時遇到困難。
對於我的示例,我使用了此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
文件,唯一的區別是Manifest
是在我的hello.exe
寫的MANIFEST
,而在Setup.exe
是Manifest
,盡管是在hello.rc
寫的表現。 O_o
EDIT2:我已經使用Resource Hacker手動更改了Manifest
組:
現在hello.exe
可以正常觸發UAC警報並以管理員身份運行。 看起來像i586-mingw32msvc-windres
的“錯誤”。 :-)
關於數字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可能已經定義好了,如果您在Google上搜索該RT_MANIFEST字詞,您會發現很多匹配項,其中包含發生情況的更多詳細信息。
用一些伏都hello.rc
,我hello.rc
在hello.rc
文件中使用它:
1 24 "hello.exe.manifest"
甚至不會搜索以了解24的含義(資源類型清單?!).. :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.