清单文件中的 requestExecutionLevel 和 CopyFile() 函数失败

发布于 2024-09-25 14:00:55 字数 1016 浏览 6 评论 0原文

只是尝试使用 CopyFile() 函数将文件从当前目录复制到 C:\windows\system32\drivers。

我还编写了清单,其中包含“requestedExecutionLevel level="highestAvailable"”,然后运行 ​​mt 将其添加到生成的可执行文件中。

当我尝试运行它时,弹出 Windows 7 UAC 对话框,我按“是”,但 CopyFile() 返回“访问被拒绝”错误。 怎么了?我应该检查什么?

我的清单文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3">
     <v3:security>
       <v3:requestedPrivileges>
         <v3:requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
       </v3:requestedPrivileges>
     </v3:security>
   </v3:trustInfo>
 </assembly>

我的一段 C 代码:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (CopyFile ("aaa.sys", "C:\\windows\\system32\\drivers", FALSE)==FALSE)
        ErrorExit ("CopyFile");

Just trying to copy a file using CopyFile() function from the current directory to C:\windows\system32\drivers.

I wrote also manifest with "requestedExecutionLevel level="highestAvailable"" in it and I run mt to add it to resulting executable.

When I try to run it, Windows 7 UAC dialog popping out, I press "Yes", but CopyFile() returning "Access Denied" error.
What is wrong? What should I check?

My manifest file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3">
     <v3:security>
       <v3:requestedPrivileges>
         <v3:requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
       </v3:requestedPrivileges>
     </v3:security>
   </v3:trustInfo>
 </assembly>

My piece of C code:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (CopyFile ("aaa.sys", "C:\\windows\\system32\\drivers", FALSE)==FALSE)
        ErrorExit ("CopyFile");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2024-10-02 14:00:55

嗯,不太确定“highestAvailable”的作用。消除所有疑问并使用“requireAdministrator”代替,它始终可以获得完整的管理员权限。另请确保使用正确的资源名称和 ID、RT_MANIFEST 和 1。

Hmm, not really sure what "highestAvailable" does. Remove all doubt and use "requireAdministrator" instead, that always works to get full admin privileges. Also make sure you use the right resource name and ID, RT_MANIFEST and 1.

月下伊人醉 2024-10-02 14:00:55
  • requireAdministrator = 始终需要管理员权限。
  • HighestAvailable = 如果是管理员组的成员,则提升。如果是普通用户,则以普通用户身份运行,无需提升权限。
  • requireAdministrator = Always require admin elevation.
  • highestAvailable = If member of admin group, elevate. If normal user, run as normal user without elevation.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文