如何请求管理员权限的程序启动时? [英] How to request administrator permissions when the program starts?

查看:252
本文介绍了如何请求管理员权限的程序启动时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的软件,能够为在Windows Vista(如果有人运行它没有管理权限,它会崩溃)管理员身份运行。

在启动其他软件,我已经看到了提示被系统像这个软件会以管理员身份运行。你要继续吗?当应用程序试图获取管理权限。

如何运行在Windows Vista?

这是C#应用程序的时候,我要求管理员权限
解决方案

以下内容添加到您的清单文件:

 < requestedExecutionLevel水平=requireAdministratoruiAccess =FALSE/>

您也可以使用 highestAvailable 的水平。

看这里有关嵌入清单文件:

<一个href=\"http://msdn.microsoft.com/en-us/library/bb756929.aspx\">http://msdn.microsoft.com/en-us/library/bb756929.aspx

PS:如果你没有一个清单文件,你可以方便地添加一个新的:

在Visual Studio中,右键单击项目 - >添加项目 - >选择应用程序清单文件(一般下的Visual C#项目)

添加的文件已经拥有上述的一部分,只是改变从 asInvoker requireAdministrator >

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.

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" />

You can also use highestAvailable for the level.

Look here about embedding manifest files:

http://msdn.microsoft.com/en-us/library/bb756929.aspx

PS: If you don't have a manifest file, you can easily add a new one:

In Visual Studio, right click project -> Add Item -> Choose Application Manifest File ( under General for Visual C# items)

The added file will already have the above part, just change the level to requireAdministrator from asInvoker

这篇关于如何请求管理员权限的程序启动时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆