程序如何请求管理员权限? [英] How does a program ask for administrator privileges?

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

问题描述

我正在 VB.NET 中开发一个小应用程序.该程序需要管理员权限才能执行某些任务.程序执行时有没有办法要求管理员权限?

I am working on a small application in VB.NET. The program needs administrator privilege for doing some tasks. Is there a way to ask for administrator privileges during the execution if the program?

更改运行应用程序的用户帐户的一般方法是什么?

What is the general way of changing the user account under which the application is running?

推荐答案

根据您的需要,有多种方法.应用程序开发人员对 UAC 的要求 中提供了一些详细信息.>

There are a number of methods depending on your needs. Some details are given in the application developer requirements for UAC.

  1. 包含一个 UAC 清单,使您的程序在启动时需要管理员权限.
  2. 使用建议的方法之一调用提升以运行进程.最好的方法之一是使用 COM 提升绰号CoCreateInstanceAsAdmin 在以管理员身份运行的 COM 对象上调用方法.这可能很难在 VB.Net 中工作.我在 C++ 中运行正常
  3. 另一种可行的方法是将需要管理员权限的代码部分隔离到使用 UAC 清单以要求管理员权限的应用程序中.在这种情况下,您的主应用程序不需要以管理员身份运行.当您需要管理员权限时,您将调用外部应用程序.
  1. Include a UAC manifest that causes your program to require administrator privileges at startup.
  2. Use one of the suggested methods for invoking an elevation to run out of process. One of the nicest is to use the COM elevation moniker and CoCreateInstanceAsAdmin to call methods on a COM object running as an administrator. This is possibly tricky to get working in VB.Net. I got it working ok in C++ though
  3. Another ok method is to isolate the parts of your code that need admin privileges into an application that uses a UAC manifest to require admin privileges. Your main app does not need to run as an admin in that case. When you require admin privilegese, you would invoke the external application.

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

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