ITPub博客

首页 > Linux操作系统 > Linux操作系统 > winform获取硬件信息

winform获取硬件信息

原创 Linux操作系统 作者:fangqm 时间:2011-04-02 15:05:04 0 删除 编辑
首先在添加引用中选中System.Management
using System.Management;
using System.Management.Instrumentation;

private void GetInfo() 
   { 
    string cpuInfo = "";//cpu序列号 
    ManagementClass cimobject = new ManagementClass("Win32_Processor"); 
    ManagementObjectCollection moc = cimobject.GetInstances(); 
    foreach(ManagementObject mo in moc) 
    { 
     cpuInfo = mo.Properties["ProcessorId"].Value.ToString(); 
     Response.Write ("cpu序列号:"+cpuInfo.ToString ()); 
    } 

    //获取硬盘ID 
    String HDid; 
    ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); 
    ManagementObjectCollection moc1 = cimobject1.GetInstances(); 
    foreach(ManagementObject mo in moc1) 
    { 
     HDid = (string)mo.Properties["Model"].Value; 
     Response.Write ("硬盘序列号:"+HDid.ToString ()); 
    } 


    //获取网卡硬件地址 

    
    
    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); 
    ManagementObjectCollection moc2 = mc.GetInstances(); 
    foreach(ManagementObject mo in moc2) 
    { 
     if((bool)mo["IPEnabled"] == true) 
      Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString()); 
     mo.Dispose(); 
    } 
   }

在添加引用中选中System.Management
再在开始部门:
using System.Management;
using System.Management.Instrumentation;

private void GetInfo() 
   { 
    string cpuInfo = "";//cpu序列号 
    ManagementClass cimobject = new ManagementClass("Win32_Processor"); 
    ManagementObjectCollection moc = cimobject.GetInstances(); 
    foreach(ManagementObject mo in moc) 
    { 
     cpuInfo = mo.Properties["ProcessorId"].Value.ToString(); 
     Response.Write ("cpu序列号:"+cpuInfo.ToString ()); 
    } 

    //获取硬盘ID 
    String HDid; 
    ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); 
    ManagementObjectCollection moc1 = cimobject1.GetInstances(); 
    foreach(ManagementObject mo in moc1) 
    { 
     HDid = (string)mo.Properties["Model"].Value; 
     Response.Write ("硬盘序列号:"+HDid.ToString ()); 
    } 


    //获取网卡硬件地址 

    
    
    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); 
    ManagementObjectCollection moc2 = mc.GetInstances(); 
    foreach(ManagementObject mo in moc2) 
    { 
     if((bool)mo["IPEnabled"] == true) 
      Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString()); 
     mo.Dispose(); 
    } 
   }

有原始数据,生成注册码的部分,按算法处理一下就行,好象这种方法挻流行。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-691563/,如需转载,请注明出处,否则将追究法律责任。

上一篇: backgroundWorker
请登录后发表评论 登录
全部评论

注册时间:2010-03-24

  • 博文量
    297
  • 访问量
    736068