c 锐利的 exe 应该要求“以管理员身份运行";打开时提示 [英] c sharp exe should ask for "run as administrator" prompt when opened

查看:22
本文介绍了c 锐利的 exe 应该要求“以管理员身份运行";打开时提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 c 锐利程序生成的 exe.当我运行 exe 时,我希望出现一个 UAC 提示,其中包含一个以管理员身份运行 exe 的选项.我已经看到默认情况下以管理员身份运行 exe 的示例.但是,如何让 UAC 要求我以管理员身份运行 exe?有什么想法吗?

I am having an exe generated by a c sharp program. when i run the exe, i want an UAC prompt to appear with an option to run the exe as administrator. I have seen examples of running an exe as admin by default. But, how do i enable the UAC to ask me for running the exe as admin? Any idea?

推荐答案

Windows vista/7/server 2008 R2 使用用户帐户控制 (UAC) 技术来确保安全,并通过限制应用程序的权限直到获得授权来保护操作系统免受恶意软件的侵害由管理员.这就是为什么我们需要让我们的应用程序以管理员身份运行的原因.这通常是在运行应用程序时完成的.过程是,右键单击应用程序,然后单击以管理员身份运行",以管理权限运行应用程序.如果假设用户忘记这样做并正常运行应用程序,则可能会出现意外行为.因为在 win vista 及更高版本中需要管理权限的所有操作(例如调用进程、使用系统驱动器等)都不会执行.

Windows vista/7/server 2008 R2 uses User Account Control (UAC) technology for security and protecting the OS from malware by limiting the privileges of an application until authorized by administrator. This is the reason why we need to make our application run as administrator. This is usually done while running the application. The process is, right click on the application and click on "Run as administrator" to run the application with administrative privileges. If suppose the user forgets to do so and runs the application normally, then unexpected behavior may be seen. Because all the actions which requires administrative privilege in win vista and above (e.g. invoking a process, using system drive, etc.) would not be performed.

所以为了避免每次都以管理员身份运行应用程序,我们可以让我们的应用程序默认以管理员身份运行.为了实现这一点,我们需要对应用程序清单进行一些调整.应用程序清单是描述应用程序的 XML 文件.

So to avoid running the application as administrator every time, we can make our application run as administrator by default. To achieve this we need some tweaking with the application manifest. An application manifest is an XML file that describes an application.

按照以下步骤使您的 .net 应用程序以管理员身份运行:

Follow the steps to make your .net application run as administrator:

步骤 1:转到项目的属性并单击查看 Windows 设置"按钮.这将打开文件app.manifest".

Step 1: Go to properties of the project and click on the "View Windows Settings" button. This will open the file "app.manifest".

第 2 步:在 requestsExecutionLevel 键中,将 level 的值更改为requireAdministrator",将 uiAccess 的值更改为False".将级别设置为requireAdministrator"意味着该应用程序仅为管理员运行,并且需要使用管理员的完全访问令牌启动该应用程序.将 uiAccess 设置为False"意味着应用程序不需要将输入驱动到桌面上另一个窗口的用户界面.不提供可访问性的应用程序应将此标志设置为 false.需要将输入驱动到桌面上的其他窗口(例如屏幕键盘)的应用程序应将此值设置为 true.

Step 2: In requestedExecutionLevel key change the value of level as "requireAdministrator" and the value of uiAccess as "False". Setting level as "requireAdministrator" means the application runs only for administrators and requires that the application be launched with the full access token of an administrator. Setting uiAccess as "False" means the application does not need to drive input to the user interface of another window on the desktop. Applications that are not providing accessibility should set this flag to false. Applications that are required to drive input to other windows on the desktop (on-screen keyboard, for example) should set this value to true.

第 3 步:保存更改,重建应用程序并将其安装在 Win Vista 或更高版本的机器上.

Step 3: Save the changes, rebuild your application and install it on Win Vista or higher box.

现在,应用程序将以管理员身份自动启动.

Now, the application would start automatically as administrator.

这篇关于c 锐利的 exe 应该要求“以管理员身份运行";打开时提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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