熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#獲取機器碼

2013-11-13 09:44:00  來源: .NET編程 

   /// <summary>

       /// 機器碼

       /// </summary>

      public class MachineCode

       {

           ///   <summary>

           ///   獲取cpu序列號

           ///   </summary>

           ///   <returns> string </returns>

           public string GetCpuInfo()

           {

               string cpuInfo = ;

               using (ManagementClass cimobject = new ManagementClass(Win_Processor))

               {

                   ManagementObjectCollection moc = cimobjectGetInstances();

  

                   foreach (ManagementObject mo in moc)

                   {

                       cpuInfo = moProperties[ProcessorId]ValueToString();

                       moDispose();

                   }

               }

               return cpuInfoToString();

           }

  

           ///   <summary>

           ///   獲取硬盤ID

           ///   </summary>

           ///   <returns> string </returns>

           public string GetHDid()

           {

               string HDid = ;

               using (ManagementClass cimobject = new ManagementClass(Win_DiskDrive))

               {

                   ManagementObjectCollection moc = cimobjectGetInstances();

                   foreach (ManagementObject mo in moc)

                   {

                       HDid = (string)moProperties[Model]Value;

                       moDispose();

                   }

               }

               return HDidToString();

           }

  

           ///   <summary>

           ///   獲取網卡硬件地址

           ///   </summary>

           ///   <returns> string </returns>

           public string GetMoAddress()

           {

               string MoAddress = ;

               using (ManagementClass mc = new ManagementClass(Win_NetworkAdapterConfiguration))

               {

                   ManagementObjectCollection moc = mcGetInstances();

                   foreach (ManagementObject mo in moc)

                   {

                       if ((bool)mo[IPEnabled] == true)

                           MoAddress = mo[MacAddress]ToString();

                       moDispose();

                   }

               }

               return MoAddressToString();

           }

       }


From:http://tw.wingwit.com/Article/program/net/201311/11438.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.