大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
把翻到的很多以前写的程序做个记录,记录学习过程,同时也方便以后查阅
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;机器型号
/*********************//
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/188751.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...