还有个好办法,就是用命令符net view 得到所有的计算机名后放到一个
txt 文本文件中,再把里面的记录一条条地读出来
以下是核心代码: 用C#来读取文本文件: private void button1_Click(object sender, System
EventArgs e) { this
openFileDialog1=new OpenFileDialog(); if(this
openFileDialog1
ShowDialog()==DialogResult
OK ) { str_text=this
openFileDialog1
FileName; StreamReader objReader = new StreamReader(str_text); string sLine=""; ArrayList arrText = new ArrayList(); while (sLine
= null) { sLine = objReader
ReadLine(); if(sLine
=null) { if (sLine
IndexOf("\\")==0) \\这句的功能是读取文本文件里所有含有”\\”前缀的记录 { arrText
Add(sLine); } } } objReader
Close(); foreach (string str_out in arrText)//遍历这个数组 this
listBox1
Add(str_out); } } 在 C#中运行 CMD 程序或其它程序返回值: private void button3_Click(object sender, System
EventArgs e) { System
Diagnostics
ProcessStartInfo psi = new System