Chinaunix首页 | 论坛 | 博客
  • 博客访问: 495271
  • 博文数量: 60
  • 博客积分: 2673
  • 博客等级: 少校
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-09 00:25
个人简介

目前主要从事C++软件开发

文章分类

全部博文(60)

文章存档

2013年(3)

2012年(3)

2010年(6)

2009年(23)

2008年(25)

我的朋友

分类:

2009-04-17 23:39:07

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

阅读(1795) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~