我用C#编写了一个程序,可以更改Windows 7登录屏幕的背景。该程序需要在System32文件夹中创建一个新文件夹,并将文件移动到其中。我在自己的电脑上测试没有问题,但在朋友的电脑上测试时,无法创建目录。他的账户类型是管理员,但我想可能是他缺少了我电脑上启用的某些权限。所以我想知道有没有办法检查用户拥有哪些权限?或者是否有绕过这个问题的方法。提前感谢!
要检测这个,你可以像这样获取一个WindowsIdentity对象:
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
最后,通过使用IsInRole()方法来检查它,像这样:
string role = "BUILTIN\\Administrators";
bool IsAdmin = principal.IsInRole(role));
然后您可以使用IsAdmin变量来确定当前用户是否为管理员。
来源 - http://csharptuning.blogspot.com/2007/09/detecting-is-current-user-is.html
requireAdministrator
选项,以便应用程序调用 UAC 提权对话框。