【问题标题】:Embed manifest file to require administrator execution level with mingw32使用 mingw32 嵌入清单文件以要求管理员执行级别
【发布时间】:2016-01-05 03:40:14
【问题描述】:

我在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 在我的@ 中写入MANIFEST 987654343@ 和 ManifestSetup.exe 虽然在 hello.rc 它是书面清单。 O_o

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

现在hello.exe 正在正常运行,触发 UAC 警报并以管理员身份运行。似乎是i586-mingw32msvc-windres 的“错误”。 :-)

【问题讨论】:

  • @JonathonReinhart 谢谢,但我也尝试了该链接上描述的内容.. 和the link it linked to 也.. 但没有任何改变.. 我已将我的hello.rc 文件更新为1 Manifest "hello.exe.manifest" .. 使用 Resource Hacker 我打开了一个需要管理员的 NSIS 安装程序(我用 makensis 编译),一切都一样;唯一不同的是清单字段在Setup.exe 文件中写入“Manifest”,在我的hello.exe 文件中写入“MANIFEST”! (See here)
  • 通常你把.rc文件编译成.res文件(不是.o
  • 请帮帮我,imgur 图片在哪里?

标签: c linux windows uac mingw32


【解决方案1】:

在我的hello.rc 文件中,我通过一些强烈的巫术来处理它:

1 24 "hello.exe.manifest"

甚至不会搜索知道 24 的用途(资源类型清单?!).. :-)

【讨论】:

    【解决方案2】:

    关于魔法巫毒数字 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 术语,您会发现很多匹配项更多详细说明正在发生的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-13
      • 2013-01-16
      • 2011-08-13
      • 2013-07-02
      • 2017-08-23
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多