验证当前登录用户的权限(控制台程序)
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
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
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步