嵌入清单文件以使用mingw32要求管理员执行级别 [英] Embed manifest file to require administrator execution level with mingw32

查看:286
本文介绍了嵌入清单文件以使用mingw32要求管理员执行级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm cross compiling an application with i586-mingw32msvc under ubuntu.

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

I'm having difficulties understanding how to embed a manifest file to require administrator execution level with mingw32.

在我的示例中,我使用了hello.c:

For my example I used this 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>

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

I compile my resource file with:

i586-mingw32msvc-windres hello.rc hello.o

我使用以下命令编译最终应用程序:

I compile my final application with:

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

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

SigCheck does not show the manifest file running sigcheck -m hello.exe.

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

Now when I run my application under Windows it does not trigger the UAC (=does not run as administrator) while when I attach the hello.exe.manifest file in the same folder it does trigger the UAC (as expected).

我想念什么?

EDIT1 :玩资源黑客我打开了我用NSIS创建的文件,唯一明智的区别是Manifest是在我的hello.exe中写为MANIFEST,在Setup.exe中是写为Manifest,尽管在​​hello.rc中是写为清单. O_o

Playing with Resource Hacker I've opened a Setup.exe file I've created with NSIS, the only sensible difference is that Manifest is written MANIFEST in my hello.exe and Manifest in Setup.exe though in hello.rc it's written Manifest. O_o

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

I've changed the Manifest group manually with Resource Hacker:

现在hello.exe可以正常触发UAC警报并以管理员身份运行.好像是i586-mingw32msvc-windres的错误". :-)

Now hello.exe is acting normally triggering the UAC alert and running as an administrator. Seems like a "bug" with i586-mingw32msvc-windres. :-)

推荐答案

关于1号和24号巫毒巫师:

With regard to the magic voodoo numbers 1 and 24:

1 24 "hello.exe.manifest"

那条线翻译成这样的东西:

That line translates to somthing like this:

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 字词,则会发现很多匹配项有关发生了什么的详细信息.

As shown above by the conditional wrappers, the RT_MANIFEST might already be defined and if you do a Google search for that RT_MANIFEST term you will find lots of hits with more details on what is going on.

这篇关于嵌入清单文件以使用mingw32要求管理员执行级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆