单一方法的C#管理员权限 [英] C# admin rights for a single methods
本文介绍了单一方法的C#管理员权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
是否可以要求一种方法的管理员权限?
像这样的东西:
Hi everybody,
Is it possible to require administrator rights for one single method?
Something like this:
[RequireAdminRightsForThisMethod()]
private void TheMethod(){
// Do something
}
我尝试以这种方式使用它:
I try to use it in this way:
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
public void MyMethod()
{
}
但我有任何成功.
我在本文 http://www.omegacoder.com/?p=82 [ ^ ]
有人可以向我解释我如何使用管理员权限执行一种方法(启动/停止服务).
我想做这样的事情:
用户按钮;
发生管理员权限请求;
如果用户允许它执行方法.
谢谢,所有!
but i have any success.
I found it in this article http://www.omegacoder.com/?p=82[^]
Can anybody explain me how i can execute one method (start/stop service) with admin rights.
I want to do something like this:
user push button;
admin right request is occur;
if user allow it method execute.
Thanks, all!
推荐答案
我怀疑您需要将方法放在dll中,以将其与其余代码分开.我知道C#会根据需要加载dll,因此也许直到那时它才需要它的管理员权限才注意到它?
I suspect you''d need to put the method in a dll to seperate it from the rest of your code. I know that C# loads the dll as it''s needed, so perhaps it won''t notice until then that it needs admin rights ?
这篇关于单一方法的C#管理员权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文