单个方法的管理员权限
是否可能需要一种方法的管理员权限?
像这样的东西:
[RequireAdminRightsForThisMethod()]
private void TheMethod(){
// Do something
}
Is it possible to require administrator rights for one single method?
Something like this:
[RequireAdminRightsForThisMethod()]
private void TheMethod(){
// Do something
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加
PrincipalPermission
< /a> 属性到您的方法以要求其执行的管理权限:以下文章对此进行了更详细的描述:
如果您是寻找一种方法来提升已经存在的进程我怀疑这是可能的,因为启动时进程级别的管理员权限被授予进程(请参阅此相关的问题)。您必须“以管理员身份”运行应用程序才能获得所需的行为。
然而,有一些技巧可能会让您做您想做的事,但请注意,这可能会带来严重的安全风险。请参阅 MSDN 论坛中的以下主题:
更新(来自评论)
看来,如果更新需要提升您的应用程序更新最好通过单独的进程(另一个可执行文件,或您的应用程序使用命令行开关调用)。对于该单独的过程,您可以按如下方式请求提升:
You can add a
PrincipalPermission
attribute to your method to demand administrative privileges for its execution:This is described in more detail in the following article:
If you are looking for a way to elevate an already existing process I doubt that this is possible as administrator privileges are given on process-level to a process upon startup (see this related question). You would have to run your application "as administrator" to get the desired behavior.
However, there are some tricks that might allow you to do what you want, but be warned that this might open up severe security risks. See the following thread in the MSDN forums:
Update (from comment)
It seems that if an update requires elevation your application update is best done by a separate process (either another executable, or your application called with a command line switch). For that separate process you can request elevation as follows:
方法可能需要管理权限才能运行,但在执行方法时不可能自动提升到管理员权限。
A method can require administrative privileges to run, but it's not possible to automatically elevate to Admin when executing a method.