相关疑难解决方法(0)

检查当前用户是否为管理员

我的应用程序需要运行一些脚本,我必须确保运行它们的用户是管理员...使用C#执行此操作的最佳方法是什么?

c# windows-administration

73
推荐指数
6
解决办法
4万
查看次数

检测信任级别

.NET应用程序如何检测运行它的信任级别?

具体来说,我想要一种方法来做类似的事情

  if (RUNNING IN GREATER THAN MEDIUM TRUST) { 
    // set private fields & properties using reflection
  }
Run Code Online (Sandbox Code Playgroud)

我目前的解决方案是使用

public static class CodeAccessSecurityTool {
    private static volatile bool _unrestrictedFeatureSet = false;
    private static volatile bool _determinedUnrestrictedFeatureSet = false;
    private static readonly object _threadLock = new object();

    public static bool HasUnrestrictedFeatureSet {
        get {
            if (!_determinedUnrestrictedFeatureSet)
                lock (_threadLock) {
                    if (!_determinedUnrestrictedFeatureSet) {
                        try {
                            // See if we're running in full trust
                            new PermissionSet(PermissionState.Unrestricted).Demand();
                            _unrestrictedFeatureSet = true;
                        } catch (SecurityException) …
Run Code Online (Sandbox Code Playgroud)

.net c#-2.0

8
推荐指数
3
解决办法
1675
查看次数

标签 统计

.net ×1

c# ×1

c#-2.0 ×1

windows-administration ×1