程序启动时如何请求管理员权限?

编程入门 行业动态 更新时间:2024-10-27 12:37:43
本文介绍了程序启动时如何请求管理员权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要我的软件能够在 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

更多推荐

程序启动时如何请求管理员权限?

本文发布于:2023-11-10 01:48:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574022.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:启动时   管理员权限   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!