清单文件中的 requestExecutionLevel 和 CopyFile() 函数失败
只是尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,不太确定“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.