C# 询问一次管理员权限 [英] C# ask once administrator privileges

查看:39
本文介绍了C# 询问一次管理员权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 C# 程序以管理员权限运行.我知道我可以通过编辑清单文件来做到这一点.但是有没有可能只询问一次用户的许可(在程序第一次启动时),而不是每次?

I want my C# program to run with administrator privileges. I know I can do this by editing the manifest file. But is there any possible way to ask the user's permission only once (at first launching of program), not every time?

推荐答案

不,你不能那样做.在 UAC 下运行时,如果应用程序需要提升,则每次进程启动时都必须显示 UAC 对话框.

No you cannot do that. When running under UAC, if an application needs to be elevated, the UAC dialog must be shown every time the process starts.

如果您想最大限度地减少用户必须面对 UAC 对话框的次数,解决方案是让您的应用程序不需要提升.如果您的应用程序执行的某些任务确实需要提升,请将它们移到单独的进程中,并且仅在用户尝试这些任务时才请求提升.所有这些问题都在 UAC 指南中的 MSDN 上有详细介绍.

If you want to minimise the amount of times the user has to face the UAC dialog, the solution is for your application not to require elevation. If there are some tasks that your application performs that do require elevation, move them into a separate process, and request elevation only when the user attempts those tasks. All these issues are covered in some detail over on MSDN in the UAC guidelines.

这篇关于C# 询问一次管理员权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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