简体   繁体   English

在运行时授予管理员权限

[英]Granting Administrator Rights During Run-Time

I'm working on a project which requires Administrator rights after clicking a button. 我正在开发一个项目,点击按钮后需要管理员权限 currently using C# and VB.NET . 目前正在使用C#VB.NET Your answer language is up to you, but better if it is in one of them. 你的答案语言取决于你,但如果是在其中一种语言中则更好。 :) :)

I already tried the following: 我已经尝试过以下方法:

  • "runas" verb with a new process but the problem is that it re-starts the application which means losing all current progress and variable values. “runas”动词带有一个新进程,但问题是它重新启动应用程序,这意味着丢失所有当前进度和变量值。
  • editing manifest file , but I "don't want to force" the user to run the application as admin. 编辑清单文件 ,但我“不想强迫”用户以管理员身份运行应用程序。

As previously said, Administrator Right required only when clicking on a button. 如前所述,仅在单击按钮时才需要管理员权限。 If it never been clicked then No rights needed! 如果从未点击过,则无需权限!

So, is there anyway to grant Administrator rights during run-time via UAC, for instance. 因此,无论如何都要通过UAC 在运行时授予管理员权限 Without restarting the application. 无需重新启动应用程序。

I've searched the web and all I got was the methods already mentioned above :) 我搜索过网络,我得到的只是上面提到的方法:)

NOTE: I found something similar to what I need in Microsoft Security Essential where it's able to grant Administrator rights without starting a new instance of the application. 注意:我发现类似于Microsoft Security Essential中所需的内容 ,它可以在不启动应用程序的新实例的情况下授予管理员权限。

MSE可以做到! Description: When running MSE , by default, you'll find in History tab that first radio box is chosen. 说明:运行MSE时 ,默认情况下,您会在“ 历史记录”选项卡中找到第一个单选框。 changing this to any other option and granting the right won't restart application therefore, maintaining current state . 将此更改为任何其他选项并授予权限将不会重新启动应用程序,因此保持当前状态

Any help is very appreciated. 非常感谢任何帮助。

There is no way to elevate during the lifetime of a process. 在过程的生命周期中无法提升。 Whether or not your process runs elevated is decided at process startup time. 在流程启动时确定您的流程是否运行升级。

I found something similar to what I need in Microsoft Security Essential where it's able to grant Administrator rights without starting a new instance of the application. 我在Microsoft Security Essential中找到了类似于我需要的东西,它可以在不启动应用程序新实例的情况下授予管理员权限。

No, MSE will be performing the elevated tasks in a separate process. 不,MSE将在单独的流程中执行提升的任务。

You don't need to close the existing process and start a new one. 您无需关闭现有流程并开始新流程。 What you are expected to do is to use a separate process to perform just the tasks that require elevation. 您应该做的是使用单独的过程来执行需要提升的任务。 That separate process does not need to show any UI. 该单独的过程不需要显示任何UI。 The elevated process can remain hidden and communicate with the process that displays the UI. 提升的进程可以保持隐藏状态并与显示UI的进程通信。 The cleanest way to achieve this is to put the elevated tasks inside an out-of-process COM server and to use CoCreateInstanceAsAdmin . 实现此目的的最简洁方法是将提升的任务放入进程外COM服务器并使用CoCreateInstanceAsAdmin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM