How to request administrator permissions when the program starts?(程序启动时如何请求管理员权限?)
问题描述
我需要我的软件能够在 Windows Vista 上以管理员身份运行(如果有人在没有管理权限的情况下运行它,它会崩溃).
I need my software to be able to run as administrator on Windows Vista (if someone runs it without administrative permissions, it will crash).
在启动其他软件时,我看到系统提示此软件将以管理员身份运行.您要继续吗?"当应用试图获取管理权限时.
When launching other software, I've seen a prompt by the system like "this software will run as administrator. do you want to continue?" when the app was trying to acquire administrative privileges.
在 Windows Vista 上运行 c# 应用时如何请求管理权限?
How do I request administrative privileges when running an c# app on Windows Vista?
推荐答案
将以下内容添加到清单文件中:
Add the following to your manifest file:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
您也可以使用 highestAvailable
作为关卡.
You can also use highestAvailable
for the level.
看看这里关于嵌入清单文件:
Look here about embedding manifest files:
http://msdn.microsoft.com/en-us/library/bb756929.aspx
PS:如果你没有清单文件,你可以很容易地添加一个新的:
PS: If you don't have a manifest file, you can easily add a new one:
在 Visual Studio 中,右键单击项目 -> 添加项目 -> 选择应用程序清单文件(在 Visual C# 项目的 General 下)
In Visual Studio, right click project -> Add Item -> Choose Application Manifest File ( under General for Visual C# items)
添加的文件已经有了上面的部分,只需将级别从asInvoker
The added file will already have the above part, just change the level to requireAdministrator
from asInvoker
这篇关于程序启动时如何请求管理员权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:程序启动时如何请求管理员权限?


- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01