C # get all workgroup and machine names for network neighbors

Source: Internet
Author: User
Internet

Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Query the computer IP on the network and user needs reference
Using System.Data;
Using System.IO;
Using System.Net;
Using System.Net.Sockets;
Using System.Threading;
Critical reference Space System.directoryservices.dll,system.management.dll
Using System.DirectoryServices;
Using System.Management;

Get all computer IP and current logged-in users in a network Neighborhood
String Strdomain;
String StrComputer;
String strshare;

DirectoryEntry Root =new DirectoryEntry ("WinNT:");
foreach (DirectoryEntry Domain in Root). Children)
{
Enumerate workgroup or domain
Strdomain=domain.name;
COMBOBOX1.ITEMS.ADD (Strdomain);
foreach (DirectoryEntry Computer in Domain.children)
{
Enumerate computers that specify a workgroup or domain

if (Computer.SchemaClassName.Equals ("Computer"))
{
Strcomputer=computer.name;
COMBOBOX2.ITEMS.ADD (StrComputer);


Enumerate shared folders for the specified computer

To get a shared folder on this computer
ManagementObjectSearcher searcher = new ManagementObjectSearcher ("SELECT * from Win32_Share");
foreach (ManagementObject share in searcher. Get ())
{
strshare=share["Name"]. ToString ();
COMBOBOX3.ITEMS.ADD (Strshare);
}

}
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.