是WindowsForm程序
从网上找了一下那方法过时了,用不了
给个例子吧(有无答案都会给分)
从网上找了一下那方法过时了,用不了
给个例子吧(有无答案都会给分)
解决方案 »
- C# Dev控件 XtraTreeList如果找不到父节点,则不显示子节??
- vs2010 datagridview读取xml文件问题
- C#调用C++写的DLL,32位win7系统失败其他正常,求解???
- 请问,Lock关键字的参数
- 如何判断某个字符串中是否包含另外一个字符串?
- 邮件中的附件base64编码生成文件问题,急!~
- 从数据库中读取了一些文件名字,并且一条一条的作为记录添加到了 ListView 控件中,
- 为什么串口的接收事件不能触发啊
- 关于switch语句的一个小问题,谢谢了!
- devexpresscn如何修改Bar的北京颜色
- 如何判断2个字符串中的仅仅一个字母区别
- showdialog 问题
SystemInformation.ComputerName
private void button1_Click(object sender, System.EventArgs e)
{//获取系统信息
try
{
this.label1.Text="用户名:"+SystemInformation.UserName;
this.label2.Text="计算机名:"+SystemInformation.ComputerName;
this.label3.Text="操作系统:"+Environment.OSVersion.Platform;
this.label4.Text="版本号:"+Environment.OSVersion.Version;
if(SystemInformation.BootMode.ToString()=="Normal")
this.label5.Text="启动方式:正常启动";
if(SystemInformation.BootMode.ToString()=="FailSafe")
this.label5.Text="启动方式:安全启动";
if(SystemInformation.BootMode.ToString()=="FailSafeWithNetwork")
this.label5.Text="启动方式:通过网络服务启动";
if(SystemInformation.Network==true)
this.label6.Text="网络连接:已连接";
else
this.label6.Text="网络连接:未连接";
this.label7.Text="显示器数量:"+SystemInformation.MonitorCount.ToString();
this.label8.Text="显示器分辨率:"+SystemInformation.PrimaryMonitorMaximizedWindowSize.Width.ToString()+"X"+
SystemInformation.PrimaryMonitorMaximizedWindowSize.Height.ToString();
}
catch(Exception Err)
{
MessageBox.Show("获取系统信息发生错误!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
方法一:使用逐个IP地址扫描的方式
利用多线程来对每个IP逐个扫描。
ComputerAddressInfo cai = new ComputerAddressInfo("192.168.1",42,53);
Thread thScan = new Thread(new ThreadStart(cai.ScanComputers));
thScan.Start();
//...
public class ComputerAddressInfo
{
private int startIP = 0;
private int endIP = 0;
private string ipPrefix = "";
private ArrayList computerList = null; public ComputerAddressInfo(string ipPrefix,int startIP,int endIP)
{
this.startIP = startIP;
this.endIP = endIP;
this.ipPrefix = ipPrefix;
computerList = new ArrayList();
}
public void ScanComputers()
{
for(int i=startIP;i<=endIP;i++)
{
string scanIP = ipPrefix +"."+i.ToString();
IPAddress myScanIP = IPAddress.Parse(scanIP);
IPHostEntry myScanHost = null;
string[] arr = new string[2];
try
{
myScanHost = Dns.GetHostByAddress(myScanIP);
}
catch
{
continue;
}
if (myScanHost != null)
{
arr[0] = myScanHost.HostName;
arr[1] = scanIP;
computerList.Add(arr);
}
}
}
} 方法二:使用Active Directory
public static ArrayList GetComputerList()
{
ArrayList list = new ArrayList();
//or use "WinNT://your_domain_name"
DirectoryEntry root = new DirectoryEntry("WinNT:");
DirectoryEntries domains = root.Children;
domains.SchemaFilter.Add("domain");
foreach (DirectoryEntry domain in domains)
{
DirectoryEntries computers = domain.Children;
computers.SchemaFilter.Add("computer");
foreach (DirectoryEntry computer in computers)
{
object[] arr = new string[3];
IPHostEntry iphe = null;
try
{
iphe = Dns.GetHostByName(computer.Name);
}
catch
{
continue;
}
arr[0] = domain.Name;
arr[1] = computer.Name;
if ( iphe != null && iphe.AddressList.Length >0 )
{
for ( int i=0;i
arr[2] += iphe.AddressList[i].ToString()+",";
arr[2] = arr[2].ToString().Remove(arr[2].ToString().Length-1,1);
}
else
arr[2] = "";
list.Add(arr);
}
}
return list;
}
网上找的..参考下吧