本文主要是介绍C#获取计算机硬件参数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
计算机名称
System.Net.Dns.GetHostName();
IP地址
System.Net.IPHostEntry localhost = System.Net.Dns.GetHostByName(Dns.GetHostName());
IPAddress localaddr = localhost.AddressList[0];
this.lblIpAddress.Text = localaddr.ToString();
操作系统名称
public string GetOSystem()
{
RegistryKey rk;
string OS = "";
rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion");
OS = rk.GetValue("ProductName").ToString();
//SystemRoot = rk.GetValue("SystemRoot").ToString();
rk.Close();
return OS;
}
CPU型号,主频,处理器
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject obj2 in searcher.Get())
{
string result = obj2.GetPropertyValue("Name").ToString() + "," + obj2.GetPropertyValue("CurrentClockSpeed").ToString() + " Mhz"; //+ Environment.ProcessorCount.ToString() + " 个处理器");
}
硬盘总容量
ManagementClass hardDisk = new ManagementClass("win32_DiskDrive");
ManagementObjectCollection hardDiskC = hardDisk.GetInstances();
foreach (ManagementObject m in hardDiskC)
{
long capacity = Convert.ToInt64(m["Size"].ToString());
string result = (capacity/1024/1024/1024).ToString();
}
内存大小
private string GetMemory()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(); //用于查询一些如系统信息的管理对象
searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" });//设置查询条件
ManagementObjectCollection collection = searcher.Get(); //获取内存容量
ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();
long capacity = 0;
while (em.MoveNext())
{
ManagementBaseObject baseObj = em.Current;
if (baseObj.Properties["Capacity"].Value != null)
{
try
{
capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
}
catch
{
return "";
}
}
}
return (capacity/1024/1024).ToString();
}
数据库版本
select @@VERSION
硬盘序列号
ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
//Win32_DiskDrive不包含SerialNumber属性。
ManagementObjectCollection moc = mc.GetInstances();
string strID = null ;
foreach( ManagementObject mo in moc )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
是否安装了IIS服务
RegistryKey regkey = Registry.LocalMachine;
RegistryKey sys = regkey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services");
DetailTreeNode IISNode = new DetailTreeNode();
CheckResult += "IIS服务检查(";
foreach (string strt in sys.GetSubKeyNames())
{
if (strt == "IISADMIN")
}
这篇关于C#获取计算机硬件参数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!