日期:2011-07-19  浏览次数:20478 次

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);         
       }     
      
      }    
    }  
   }