管理运行权限测试申请 [英] Testing application for Administrative Running Rights
问题描述
我想要一种可靠的方法来测试应用程序是否通过 UAC 框运行并具有完全管理权限.之前想过在C:\Windows\下建一个文件夹进行测试,结果在其他电脑上运行失败!
I want a sure-shot method to test if the application was run via the UAC box and has full administrative rights. Earlier, I thought of making a folder in C:\Windows\ for testing but running it on other computers proved to be a failure!
UAC 框为计算机提供了执行任何操作的所有管理权限(包括在需要权限的地方创建文件夹和创建文件),并确保任何所谓或创建的子程序也确实具有与父母.
The UAC box provides all administrative rights to the computer to do anything(including making folders and creating files in places which needs there rights) and also makes sure that any child program so called or created also does have the same rights as the parent.
是否有一种可靠的方法可以测试我的应用程序是否已获得用户在运行应用程序时可以获得的所有管理权限?如果是的话,我很高兴有一段代码工作!
Is there a sure-shot way to test if my application has been provided all the administrative rights that I can maximum get by the user while running the application or not? If yes, I would be glad to have to piece of code-work!
推荐答案
C#:
using System.Security.Principal;
...
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
VB.Net:
Imports System.Security.Principal
...
Dim identity = WindowsIdentity.GetCurrent()
Dim principal = new WindowsPrincipal(identity)
Dim isElevated as Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)
这篇关于管理运行权限测试申请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!