如题,也可转成,如何验证当前的操作系统用户是系统管理员,具有最高权限
解决方案 »
- WCF服务的方法名固定,但是地址是动态的。怎么动态调用WCF服务?
- 急急(在线等):httpwebrequest 模拟登录 带上cookie和要提交的数据,但是 就是登录不了呢!!!!
- 找个类
- HttpWebRequest如何post一个页面后返回结果
- c#中static干什么用的?
- C#操作word文档,网word模版的域里面填充数据该怎么做!!
- vs2005 连接sql2000报错
- 有关C#编程的几个基本问题(每题20分)
- 看完了《C#入门经典》想看本C# winform编程的书,望推荐一下
- 可以一下读出datagrid里所有的数据吗? 怎么读出来?
- 如何将exe文件放在资源文件中,并在程序中使用
- 请问如何把信息写入注册表
net localgroup administrators |find "%username%">nul
if %errorlevel% equ 0 echo 当前用户为系统管理员
这只能通过命令来执行,在 net 里面有什么方法能获得命令执行的返回值呢
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;namespace c2
{
class Program
{
static void Main(string[] args)
{
if (runcmd("net localgroup administrators |find \"%username%\"").IndexOf(System.Environment.UserName) >= 0)
Console.WriteLine("Admin");
else
Console.WriteLine("No Admin!");
Console.Read();
}
private static string runcmd(string command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
return p.StandardOutput.ReadToEnd();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;namespace c2
{
class Program
{
static void Main(string[] args)
{
if (runcmd("net localgroup administrators").IndexOf(System.Environment.UserName) >= 0)
Console.WriteLine("Admin");
else
Console.WriteLine("No Admin!");
Console.Read();
}
private static string runcmd(string command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
return p.StandardOutput.ReadToEnd();
}
}
}
//查找当前系统登陆的用户是否在 Administrators组中