如果可能的话以管理员身份运行,如果不能:以有限的权限运行?
我需要根据用户权限更改应用程序的行为:
- 当我的应用程序可以以管理员身份运行时
- 当我的应用程序具有有限权限时
由于“requireAdministrator”嵌入在清单中,因此相同的 .exe 无法在 (1) 和(2)同时。
处理这个问题的最佳方法是什么?我计划打包两个可执行文件(其中一个带有“requireAdministrator”)并决定运行哪一个。 有人有其他建议吗?
I need to change the behavior of my application depending on user privileges:
- When my application can run as Administrator
- When my application has limited privileges
Since "requireAdministrator" is embedded within the manifest, the same .exe can't work on (1) and (2) at the same time.
What's the best way to deal with this issue? I am planning to pack two executables (one with "requireAdministrator") and decide which one to run.
Someone have other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用要求最高可用的清单,而不是 requireAdministrator 或 asInvoker。如果只同意提升的人正在运行它,这将会提升,但如果是需要 OTS 提示并输入管理员 ID 和密码的人,则不会。我自己并不关心它,因为你无法在知道自己是否拥有特权的情况下放心地编写代码。但这就是实现您所要求的方法。
You can use a manifest that asks for highestAvailable instead of requireAdministrator or asInvoker. This will elevate if a person who can just consent to elevating is running it, but won't if it's someone who would need the OTS prompt and entering an admin id and password. I don't care for it myself, since you can't write your code in confidence knowing whether you have the privileges or not. But this is how to achieve what you're asking for.