How get list of local network computers?

前端 未结 6 464
甜味超标
甜味超标 2020-12-01 04:47

I am trying to get a list of local network computers. I tried to use NetServerEnum and WNetOpenEnum API, but both API return error code 6118

6条回答
  •  误落风尘
    2020-12-01 05:22

    You will need to use the System.DirectoryServices namespace and try the following:

    DirectoryEntry root = new DirectoryEntry("WinNT:");
    
    foreach (DirectoryEntry computers in root.Children)
    {
        foreach (DirectoryEntry computer in computers.Children)
        {
            if (computer.Name != "Schema")
            {
                 textBox1.Text += computer.Name + "\r\n";
            }
        }
    }
    

    It worked for me.

提交回复
热议问题