如何在C#項目中獲取硬件參數(shù)-創(chuàng)新互聯(lián)

如何在C#項目中獲取硬件參數(shù)?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

員工經(jīng)過長期磨合與沉淀,具備了協(xié)作精神,得以通過團隊的力量開發(fā)出優(yōu)質(zhì)的產(chǎn)品。創(chuàng)新互聯(lián)堅持“專注、創(chuàng)新、易用”的產(chǎn)品理念,因為“專注所以專業(yè)、創(chuàng)新互聯(lián)網(wǎng)站所以易用所以簡單”。公司專注于為企業(yè)提供成都網(wǎng)站建設、網(wǎng)站設計、微信公眾號開發(fā)、電商網(wǎng)站開發(fā),微信小程序開發(fā),軟件按需網(wǎng)站策劃等一站式互聯(lián)網(wǎng)企業(yè)服務。

C# 獲取硬件參數(shù)的實現(xiàn)方法

示例代碼:

private static string GetIdentifier(string wmiClass, string wmiProperty, string wmiMustBeTrue) 
    { 
      string result = ""; 
      System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); 
      System.Management.ManagementObjectCollection moc = mc.GetInstances(); 
      foreach (System.Management.ManagementObject mo in moc) 
      { 
        if (mo[wmiMustBeTrue].ToString() == "True") 
        { 
          //Only get the first one 
          if (result == "") 
          { 
            try 
            { 
              result = mo[wmiProperty].ToString(); 
              break; 
            } 
            catch 
            { 
            } 
          } 
        } 
      } 
      return result; 
    } 
 
 
    private static string GetIdentifier(string wmiClass, string wmiProperty) 
    { 
      string result = ""; 
      System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); 
      System.Management.ManagementObjectCollection moc = mc.GetInstances(); 
      foreach (System.Management.ManagementObject mo in moc) 
      { 
        //Only get the first one 
        if (result == "") 
        { 
          try 
          { 
            result = mo[wmiProperty].ToString(); 
            break; 
          } 
          catch 
          { 
          } 
        } 
      } 
      return result; 
    } 
 
 
 
 
 
 
// cpu id  
GetIdentifier("Win32_Processor", "UniqueId"); 
 
 
//processor id 
GetIdentifier("Win32_Processor", "ProcessorId"); 
 
 
//processor name 
GetIdentifier("Win32_Processor", "Name"); 
 
 
 
 
//Manufacturer 
GetIdentifier("Win32_Processor", "Manufacturer"); 
 
 
 
 
//BIOS Identifier 
    private static string GetBiosId() 
    { 
      return GetIdentifier("Win32_BIOS", "Manufacturer") 
      + GetIdentifier("Win32_BIOS", "SMBIOSBIOSVersion") 
      + GetIdentifier("Win32_BIOS", "IdentificationCode") 
      + GetIdentifier("Win32_BIOS", "SerialNumber") 
      + GetIdentifier("Win32_BIOS", "ReleaseDate") 
      + GetIdentifier("Win32_BIOS", "Version"); 
    } 
    //Main physical hard drive ID 
    private static string GetDiskId() 
    { 
      return GetIdentifier("Win32_DiskDrive", "Model") 
      + GetIdentifier("Win32_DiskDrive", "Manufacturer") 
      + GetIdentifier("Win32_DiskDrive", "Signature") 
      + GetIdentifier("Win32_DiskDrive", "TotalHeads"); 
    } 
    //Motherboard ID 
    private static string GetBaseId() 
    { 
      return GetIdentifier("Win32_BaseBoard", "Model") 
      + GetIdentifier("Win32_BaseBoard", "Manufacturer") 
      + GetIdentifier("Win32_BaseBoard", "Name") 
      + GetIdentifier("Win32_BaseBoard", "SerialNumber"); 
    } 
    //Primary video controller ID 
    private static string GetVideoId() 
    { 
      return GetIdentifier("Win32_VideoController", "DriverVersion") 
      + GetIdentifier("Win32_VideoController", "Name"); 
    } 
    //First enabled network card ID 
    private static string GetMacId() 
    { 
      return GetIdentifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled"); 
    }

看完上述內(nèi)容,你們掌握如何在C#項目中獲取硬件參數(shù)的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站制作公司行業(yè)資訊頻道,感謝各位的閱讀!

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網(wǎng)站題目:如何在C#項目中獲取硬件參數(shù)-創(chuàng)新互聯(lián)
文章鏈接:http://bm7419.com/article36/ipdsg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)站建設、做網(wǎng)站App開發(fā)、品牌網(wǎng)站制作、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設