大家好,又见面了,我是你们的朋友全栈君。
把翻到的很多以前写的程序做个记录,记录学习过程,同时也方便以后查阅
https://github.com/Yiomo/GetInfo
该APP会获取部分机器信息并且在当前目录下生成一份TXT报告
1.引用
using System; using System.Collections.Specialized; using System.IO; using System.Management; using System.Net; using System.Net.Sockets; using System.Windows; using System.Windows.Input; using System.Windows.Media;
2.控件
省略一堆textblock一类的控件,能输出就行
3.获取机器名称
string machineName = Environment.MachineName; bl1.Text = machineName;
4.获取MAC地址
try { using (ManagementClass mc = new ManagementClass(“Win32_NetworkAdapterConfiguration”)) { using (ManagementObjectCollection moc = mc.GetInstances()) { string macAddress = “”; foreach (ManagementObject mo in moc) { if ((bool)mo[“IPEnabled”] == true) { macAddress = mo[“MacAddress”].ToString(); break; } } bl2.Text = macAddress; } } } catch { bl2.Text = “unknown”; } finally { }
5.判断32/64位系统
bool is64OS = Environment.Is64BitOperatingSystem; if (is64OS == true) bl3.Text = “64 bits OS”;//64位 else bl3.Text = “32 bits OS”;//32位
6.获取硬盘信息
string HDSN = “”; ManagementClass cimobject = new ManagementClass(“Win32_DiskDrive”); ManagementObjectCollection moc1 = cimobject.GetInstances(); foreach (ManagementObject mo in moc1) { HDSN = (string)mo.Properties[“Model”].Value; } ManagementClass mc1 = new ManagementClass(“Win32_PhysicalMedia”); ManagementObjectCollection moc2 = mc1.GetInstances(); string HDID = “”; foreach (ManagementObject mo in moc2) { HDID = mo.Properties[“SerialNumber”].Value.ToString().Trim(); break; } bl4.Text = HDSN; bl5.Text = HDID;
7.IPV4
string[] GetLocalIpv4() { IPAddress[] localIPs; localIPs = Dns.GetHostAddresses(Dns.GetHostName()); StringCollection IpCollection = new StringCollection(); foreach (IPAddress ip in localIPs) { if (ip.AddressFamily == AddressFamily.InterNetwork)///AddressFamily.InterNetwork代表IPV4地址,不包含V6 IpCollection.Add(ip.ToString()); } string[] IpArray = new string[IpCollection.Count]; IpCollection.CopyTo(IpArray, 0); return IpArray; }
void ShowIP() { foreach (string ip in GetLocalIpv4()) { bl6.Text = ip.ToString(); } return; }
ShowIP();
8.IPV6
string ip = “”; IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList; for (int i = 0; i < addressList.Length; i ) { ip = addressList[i].ToString(); } bl7.Text = ip;
9. 获取厂商和机器型号(manufacturer)(model)
ManagementClass mc2 = new ManagementClass(“Win32_ComputerSystem”); ManagementObjectCollection moc3 = mc2.GetInstances();
if (moc3.Count != 0) { foreach (ManagementObject mo in mc2.GetInstances()) { bl1.Text =mo[“Manufacturer”].ToString();///制造厂商 } }
foreach (ManagementObject m in moc3) { PCV = m[“model”].ToString (); } bl2.Text = PCV;机器型号
/*********************//
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188751.html原文链接:https://javaforall.cn