【问题标题】:Attach UAC Manifest file to any PE using Update Resource使用更新资源将 UAC 清单文件附加到任何 PE
【发布时间】:2011-05-29 09:15:57
【问题描述】:

我想构建一个简单的工具来将 UAC 清单文件附加到给定的 exe 文件,代码可以正常工作,但没有任何反应。我必须说,当我使用 mainfest 文件手动编译时,它可以正常工作。

procedure TForm1.Button1Click(Sender: TObject);
var
myRes:THandle;
test:PChar;
begin
test:='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+#13#10+
'<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">'+#13#10+
'<assemblyIdentity version="1.1.1.1"'+#13#10+
'processorArchitecture="X86"'+#13#10+
'name="[APP TO TEST WITH]"'+#13#10+ 
'type="win32"/>'+#13#10+
'<description>elevate execution level</description>'+#13#10+
'<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">'+#13#10+
'<security>'+#13#10+
'<requestedPrivileges>'+#13#10+
'<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>'+#13#10+
'</requestedPrivileges>'+#13#10+
'</security>'+#13#10+
'</trustInfo>'+#13#10+
'</assembly> ';
myRes := BeginUpdateResource('testuac.exe',false);
UpdateResource(myRes,MakeIntResource(24),'1',1033,test,length(test));
EndUpdateResource(myres,false);
ShowMessage(SysErrorMessage(GetLastError));
end;//Compiled with Delphi 7

代码工作资源出现在 exe 中,但它不起作用。知道为什么吗?

【问题讨论】:

  • msdn.microsoft.com/en-us/library/bb756929.aspx - 这解释了如何从代码中制作它。还要注意 MANIFEST_RESOURCE_ID RT_MANIFEST "IsUserAdmin.exe.manifest" 行。
  • 那行不是“如何从代码中实现”,@RBA。这就是如何定义一个.rc文件被编译成一个.res文件,并且该文件的内容在链接时链接到一个程序。

标签: delphi resources uac


【解决方案1】:

您似乎无法为清单资源指定任意名称,请尝试

UpdateResource(myRes,MakeIntResource(24),MakeIntResource(1),1033,test,length(test));


来自 winuser.h:

#define CREATEPROCESS_MANIFEST_RESOURCE_ID MAKEINTRESOURCE( 1)


来自Specifying a Default Activation Context

资源 ID 1 (CREATEPROCESS_MANIFEST_RESOURCE_ID) .EXE 时隐式激活 被执行。

【讨论】:

  • 文档链接引用了社区内容中的引用。该内容引用的链接 (RT_MANIFEST resource, and ISOLATION_AWARE_ENABLED) 来自张俊峰的 Microsoft 博客,更详细地解释了..
  • @opc0de - 通过我的测试它可以工作。你把一个整数放在右边; MakeIntResource(1)不是 MakeIntResource('1');
  • 对不起,我没有很好地测试,因为我搞砸了清单,但现在我编辑了它并且效果很好。非常感谢伙伴
猜你喜欢
  • 2014-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多