c# 枚举系统用户

walkline 2008-09-23 09:49:17
可以用c#枚举出操作系统上所有的用户吗?谢谢
...全文
49 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdgphc 2008-09-24
  • 打赏
  • 举报
回复
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace c2
{
class Program
{
static void Main(string[] args)
{
string[] users = Regex.Split(Regex.Match(runcmd("net user"), @"(?<=-\s)[\w\s]+(?=命令成功完成)").Value.Trim(), @"\s+");

foreach (string u in users)
Console.WriteLine(u);
Console.ReadKey();
}

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();
}
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧