using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//查询网络上的计算机IP和用户需要引用
using System.Data;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
//关键引用空间System.directoryservices.dll,System.Management.dll
using System.DirectoryServices;
using System.Management;
//获取网络邻居中的所有计算机IP和当前登录用户
string strDomain;
string strComputer;
string strShare;
DirectoryEntry root =new DirectoryEntry("WinNT:");
foreach(DirectoryEntry Domain in root.Children)
{
//枚举工作组或域
strDomain=Domain.Name;
comboBox1.Items.Add(strDomain);
foreach(DirectoryEntry Computer in Domain.Children)
{
//枚举指定工作组或域的计算机
if(Computer.SchemaClassName.Equals("Computer"))
{
strComputer=Computer.Name;
comboBox2.Items.Add(strComputer);
//枚举指定计算机的共享文件夹
//获取本机共享的文件夹
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share");
foreach (ManagementObject share in searcher.Get())
{
strShare=share["Name"].ToString();
comboBox3.Items.Add(strShare);
}
}
}
}
本文介绍了一段使用C#编写的代码,该代码能够枚举网络中的计算机及其共享文件夹。通过调用特定的API和类,如DirectoryEntry和ManagementObjectSearcher,实现了对网络上计算机的搜索及共享资源的获取。

被折叠的 条评论
为什么被折叠?



