时间:2020-10-07 14:28:12 | 栏目:.NET代码 | 点击:次
本文实例讲述了C#获取客户端相关信息的方法。分享给大家供大家参考。具体如下:
【本机IP地址】
第一种方法:
IPHostEntry hostentry = Dns.Resolve(Dns.GetHostName()); IPAddress address=hostentry.AddressList[0];
第二种方法:
【判断当前用户是否连网】
PingReply reply = new Ping().Send(address); if (reply.Status == IPStatus.Success) MessageBox.Show("Ping successfully."); else MessageBox.Show("Ping failure.");
【获取当前客户端硬盘盘符】
SelectQuery select = new SelectQuery("select * from win32_logicaldisk"); ManagementObjectSearcher mos = new ManagementObjectSearcher(select); foreach (ManagementObject disk in mos.Get()) { string msg = disk["Name"].ToString(); DriveInfo info = new DriveInfo(msg); switch (info.DriveType.ToString()) { case "Unknown": label1.Text += msg + "这是未知设备__"; break; case "NoRootDirectory": label1.Text += msg + "这是未分区__"; break; case "Removable": label1.Text += msg + "这是可以动磁盘__"; break; case "Fixed": label1.Text += msg + "这是硬盘__"; break; case "Network": label1.Text += msg + "这是网络驱动器__"; break; case "CDRom": label1.Text += msg + "这是光驱__"; break; } }
【获取当前显示的长宽】
宽:
【获取客户端进程信息】
foreach (System.Diagnostics.Process p in processes) { if (p.ProcessName == "IntelliTrace") { p.Kill(); } }
【判断客户端是否安装声卡】
[DllImport("winmm.dll", EntryPoint = "waveOutGetNumDevs")] public static extern int waveOutGetNumDevs(); private void button1_Click(object sender, EventArgs e) { if (waveOutGetNumDevs() != 0) { MessageBox.Show("已经安装声卡"); } else { MessageBox.Show("未安装声卡"); } }
【获取计算机名称和当前登录用户】
计算机名称:
希望本文所述对大家的C#程序设计有所帮助。