Получить список компьютеров в сети - C#
Формулировка задачи:
Доброго времени суток!!!
Как получить список компьютеров в сети и произвести листинг открытых директорий на них?
Решение задачи: «Получить список компьютеров в сети»
textual
Листинг программы
/// <summary>
/// method for getting the names of all shared folders on local system
/// </summary>
/// <returns>Generic list of all share names</returns>
public void GetShareNames()
{
Process proc = new Process(); // This creates a new process
proc.StartInfo.FileName = "cmd"; // Tells it to launch a command prompt
// This line runs a command called "net view"
// which is a built in windows command that returns all the shares
// on a network
proc.StartInfo.Arguments = "/C net view";
// This property redirects the output of the command ran
// to the StandardOutput object we use later
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
// This tells the program to show the command window or not
// set to true to hide the window
proc.StartInfo.CreateNoWindow = false;
proc.Start();
// Sets all the output into a string
string data = proc.StandardOutput.ReadToEnd();
int start = 0;
int stop = 0;
// This parses through the output string
// and grabs each share and outputs it.
// you can save the strings into an array and add
// them to a list box or something if you wanted to.
while (true)
{
start = data.IndexOf('\\', start);
if (start == -1)
break;
stop = data.IndexOf('\n', start);
listBox1.Items.Add(data.Substring(start, stop - start));
start = stop;
}
}