如何保证我的 WPF 应用程序的永久管理员权限
我已经阅读了很多有关 Windows 7 中的 UAC evelation 等的文章,但我没有成功找到我的问题的答案:如何保证我的应用程序始终“以管理员身份运行”,我正在寻找一些代码片段或其他东西。任何帮助将不胜感激。 / 并且请不要发送垃圾邮件,例如:“您确定需要此权限和访问权限吗” - 是的,我确信应用程序需要它们。
I have read a lot of articles for UAC evelation in Windows 7 and so on, but I did not suceed in finding an answer to my question : How to guarantee that my application will be always "Run as administrator" , I am looking for some code snippet or something else. Any help will be appreciated. / And please don't spam with posts like : "Are you sure that you need this priviligies and access" - Yes I am sure the application needs them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用以下部分将应用程序清单添加到您的应用程序:
Add an app manifest to your app with the following section:
这篇 MSDN 文章解释了如何使 UAC 友好:
教您的应用程序如何与 Windows Vista 用户帐户控制完美配合
第 使用应用程序标记所需的权限清单 就是您正在寻找的内容。
This MSDN article explains how to be UAC friendly:
Teach Your Apps To Play Nicely With Windows Vista User Account Control
Chapter Marking Required Privileges Using an Application Manifest is what you are looking for.
Windows 没有能力授予应用程序管理权限;权限由用户授予。
如果运行您的应用程序的用户没有管理权限,那么您的应用程序将不具有管理权限。
程序不能因为程序希望而“保证永久”管理员权限。必须向用户授予权限。
但是应用程序的请求不可能被授予管理权限。
Windows does not have the capability to grant an application administrative privileges; permissions are granted by user.
If the user running your application does not have administrative permissions, then your application will not have administrative permissions.
A program cannot be "guaranteed permanent" administrator permissions because a program wishes it. The user must be granted the permissions.
But the request that an application be granted administrative privileges is not possible.
如果我理解正确的话,您的应用程序将成为用户 shell,即它将取代 Windows 资源管理器。在这种情况下,您可以通过多种方法绕过 UAC,例如,使用凭据管理器捕获用户的凭据并使用它们创建新令牌,或者通过挂钩 LogonUser 函数并捕获未修改的令牌。
然而,迄今为止最简单的方法是禁用 UAC。除非用户将运行 Internet Explorer 或其他利用 UAC 沙箱的程序,否则可能没有理由在您的场景中打开 UAC。
If I understand correctly, your application is going to be the user shell, i.e., it will replace Windows Explorer. There are various ways you could bypass UAC in this scenario, for example, by using a credential manager to capture the user's credentials and use them to create a new token, or by hooking the LogonUser function and capturing the unmodified token.
However, the simplest approach by far would be to disable UAC. Unless the user will be running Internet Explorer or another program that takes advantage of UAC sandboxing, there is probably no reason to leave UAC turned on in your scenario.