zoukankan      html  css  js  c++  java
  • 验证当前登录用户的权限(控制台程序)

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Diagnostics;
     6 
     7 namespace c2
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             if (runcmd("net localgroup administrators |find \"%username%\"").IndexOf(System.Environment.UserName) >= 0)
    14                 Console.WriteLine("Admin");
    15             else
    16                 Console.WriteLine("No Admin!");
    17             Console.Read();
    18         }
    19         private static string runcmd(string command)
    20         {
    21             Process p = new Process();
    22             p.StartInfo.FileName = "cmd.exe";           
    23             p.StartInfo.Arguments = "/c " + command;    
    24             p.StartInfo.UseShellExecute = false;        
    25             p.StartInfo.RedirectStandardInput = true;   
    26             p.StartInfo.RedirectStandardOutput = true;  
    27             p.StartInfo.RedirectStandardError = true;   
    28             p.StartInfo.CreateNoWindow = true;          
    29             p.Start();   
    30             return p.StandardOutput.ReadToEnd();   
    31         }
    32     }
    33 }
    34 

    net localgroup administrators |find \"%username%\"").IndexOf(System.Environment.UserName) >= 0

    用这个命令也行

    微软BI技术交流群:316744959 武汉NET技术群:961108969 NET技术群:21386099 本人具有丰富的系统开发经验,承接系统开发,小程序,NET系统开发,BI开发,有需求联系微信手机:15010195887
  • 相关阅读:
    如何设置 ComboBox 下拉列表的高度或间距
    winform中ComboBox利用AutoComplete属性实现模糊查询(有缺陷)
    C#中combobox 控件属性、事件、方法
    ComboBox TextUpdate事件
    C#判断页面中的多个文本框输入值是否有重复的实现方法
    c# winfrom程序中 enter键关联button按钮
    WinForm 中ComboBox 绑定总结
    c# 实现ComboBox自动模糊匹配
    C#中ComboBox动态绑定赋值
    WinForm 中 comboBox控件之数据绑定
  • 原文地址:https://www.cnblogs.com/Impulse/p/1289653.html
Copyright © 2011-2022 走看看