控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

C#获得硬件和操作系统各项信息

作者:佚名 出处:互联网 2011年10月12日 阅读:

C#获得硬件和操作系统各项信息

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Management;
  5
  6 namespace MonitorSoftware
  7 {
  8     internal class Computer
  9     {
 10         internal static string CPUName
 11         {
 12             get
 13             {
 14                 string cpuinfo = "unknow";
 15                 ManagementClass mc = new ManagementClass("win32_processor");
 16                 ManagementObjectCollection moc = mc.GetInstances();
 17
 18                 foreach (ManagementObject mo in moc)
 19                 {
 20                     cpuinfo = mo["Name"].ToString();
 21                 }
 22                 moc.Dispose();
 23                 return cpuinfo;
 24             }
 25         }
 26        
 27         private static string CPUSN
 28         {
 29             get
 30             {
 31                 string sn = "";//cpu序列号
 32                 ManagementClass cimobject = new ManagementClass("Win32_Processor");
 33                 ManagementObjectCollection moc = cimobject.GetInstances();
 34                 foreach (ManagementObject mo in moc)
 35                 {
 36                     sn = mo.Properties["ProcessorId"].Value.ToString();
 37                 }
 38                 return sn;
 39             }
 40         }
 41        
 42           private static string HardDiskID
 43         {
 44             get
 45             {
 46                 string hdid="";
 47                 ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
 48                 ManagementObjectCollection moc1 = cimobject1.GetInstances();
 49                 foreach (ManagementObject mo in moc1)
 50                 {
 51                     hdid = mo.Properties["Model"].Value.ToString ();
 52                 }
 53
 54                 return hdid;
 55             }
 56         }
 57
 58         internal static string MAC
 59         {
 60             get
 61             {
 62                 string mac = "unknow";
 63                 ManagementClass mAdapter = new ManagementClass("Win32_NetworkAdapterConfiguration");
 64                 ManagementObjectCollection moc = mAdapter.GetInstances();
 65                 foreach (ManagementBaseObject mo in moc)
 66                 {
 67                     if ((bool)mo["IpEnabled"] == true)
 68                     {
 69                         mac = mo["MacAddress"].ToString();
 70                     }
 71                 }
 72                 moc.Dispose();
 73                 return mac;
 74             }
 75           
 76        }
 77
 78         internal static string MemorySize
 79         {
 80             get
 81             {
 82                 ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
 83                 ManagementObjectCollection moc = mc.GetInstances();
 84                 double sizeAll = 0.0;
 85                 foreach (ManagementObject mo in moc)
 86                 {
 87                     if (mo.Properties["TotalVisibleMemorySize"].Value != null)
 88                     {
 89                         sizeAll += Convert.ToDouble(mo.Properties["TotalVisibleMemorySize"].Value.ToString());
 90                     }
 91                 }
 92                 //sizeAll /= 1000000;
 93                 moc.Dispose();
 94                 return sizeAll.ToString("0.###");
 95             }
 96
 97         }
 98
 99         internal static string[] IPAddress
100         {
101             get
102             {
103                 string hostname = System.Net.Dns.GetHostName();
104                 System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);
105                 string[] ips = new string[ipEntry.AddressList.Length];
106                 for (int i = 0; i < ipEntry.AddressList.Length; i++)
107                 {
108                     ips[i] = ipEntry.AddressList[i].ToString();
109                 }
110                 return ips;
111             }
112         }
113
114         internal static string OSType
115         {
<span style="color%
 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统