我需要我的软件能够在 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:
msdn.microsoft/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
更多推荐
程序启动时如何请求管理员权限?
发布评论