日期:2014-05-18 浏览次数:21068 次
protected override void OnStart(string[] args)
            {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            //查看本机端口占用情况
            p.StandardInput.WriteLine("netstat -an");
            p.StandardInput.WriteLine("exit");
            //
            StreamReader reader = p.StandardOutput;//截取输出流
            string strLine = reader.ReadLine();//每次读取一行
            while (!reader.EndOfStream)
                {
                strLine = reader.ReadLine();//再下一行  
                }
            p.WaitForExit();//等待程序执行完退出进程
            p.Close();//关闭进程
            reader.Close();//关闭流
 [color=#FF0000]这里strLine获取到的信息只有一句C:\WINDOWS\system32>exit[/color]}