vb.net 程序如何请求管理员权限?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/90674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:49:31  来源:igfitidea点击:

How does a program ask for administrator privileges?

vb.netprivileges

提问by Niyaz

I am developing an application using vb.net. For performing some tasks the application needs administrator privileges in the machine. How to ask for the privileges during the execution of the program?

我正在使用 vb.net 开发应用程序。为了执行某些任务,应用程序需要机器的管理员权限。程序执行过程中如何请求权限?

What is the general method of switching user accounts for executing an application? In other words, is there some way for an application to run under an arbitrary user account?

切换用户帐户以执行应用程序的一般方法是什么?换句话说,有没有办法让应用程序在任意用户帐户下运行?

采纳答案by Niyaz

You can edit the UAC Settings(in VB 2008) which is located in the Project Settings. Look for the line that says

您可以编辑位于项目设置中的UAC 设置(在 VB 2008 中)。寻找说的那一行

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

Change level="asInvoker" to

将 level="asInvoker" 更改为

  1. level="asInvoker"(same access token as the parent process)
  2. level="requireAdministrator(require full administrator)
  3. level="highestAvailable"(highest privileges available to the current user)
  1. level="asInvoker"(与父进程相同的访问令牌)
  2. level="requireAdministrator(需要完全管理员)
  3. level="highestAvailable"(当前用户可用的最高权限)

回答by splattne

There are several articles on the Internet about developing elevated processes in Vista, but essentially elevation requests involve decorating .NET assemblies and WIN32 executables with elevation status in the application manifest file (may be embedded or side-by-side).

Internet 上有几篇关于在 Vista 中开发提升进程的文章,但本质上提升请求涉及在应用程序清单文件(可以嵌入或并行)中使用提升状态装饰 .NET 程序集和 WIN32 可执行文件。

There is an excellent blog post about your question which provides the code you'll probably need:

有一篇关于您的问题的优秀博客文章提供了您可能需要的代码:

.NET Wrapper for COM Elevation

用于 COM 提升的 .NET 包装器

回答by Bryan Anderson

I have not done this yet but I believe you go to (in VS 2008) Project Settings -> Application Tab and click on the "View UAC Settings" button. This opens up your app.manifest file. In there is a tag which I think holds the options you're looking for. Mine has some options commented out which should get you started:

我还没有这样做,但我相信你去(在 VS 2008 中)项目设置 -> 应用程序选项卡,然后单击“查看 UAC 设置”按钮。这将打开您的 app.manifest 文件。我认为有一个标签包含您正在寻找的选项。我的一些选项被注释掉了,应该让你开始:

回答by Metexu

IN VS 2015: Go to: Project -> (name of project) Properties... -> Application -> View Windows Settings and find in app.manifest (line 19): And change asInvoker to:

在 VS 2015 中:转到:项目 ->(项目名称)属性... -> 应用程序 -> 查看 Windows 设置并在 app.manifest(第 19 行)中找到:并将 asInvoker 更改为:

  1. "asInvoker" (same access token as the parent process)
  2. "requireAdministrator (require full administrator)
  3. "highestAvailable" (highest privileges available to the current user)
  1. “asInvoker”(与父进程相同的访问令牌)
  2. "requireAdministrator (需要完全管理员)
  3. “highestAvailable”(当前用户可用的最高权限)