這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)利用C#怎么獲取硬盤和CPU信息,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
成都創(chuàng)新互聯(lián)公司憑借專業(yè)的設(shè)計團(tuán)隊扎實的技術(shù)支持、優(yōu)質(zhì)高效的服務(wù)意識和豐厚的資源優(yōu)勢,提供專業(yè)的網(wǎng)站策劃、做網(wǎng)站、成都網(wǎng)站設(shè)計、網(wǎng)站優(yōu)化、軟件開發(fā)、網(wǎng)站改版等服務(wù),在成都十年的網(wǎng)站建設(shè)設(shè)計經(jīng)驗,為成都千余家中小型企業(yè)策劃設(shè)計了網(wǎng)站。第一步:程序獲得運(yùn)行機(jī)的標(biāo)示:硬盤號,CPU信息
//獲取硬盤號 private string GetDiskID() { try { //獲取硬盤ID String HDid = ""; ManagementClass mc = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { HDid = (string)mo.Properties["Model"].Value; } moc = null; mc = null; return HDid; } catch { return ""; } finally { } } //獲取CPU信息 private string GetCpuInfo() { try { string cpuInfo = "";//cpu序列號 ManagementClass cimobject = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = cimobject.GetInstances(); foreach (ManagementObject mo in moc) { cpuInfo = mo.Properties["ProcessorId"].Value.ToString(); } return cpuInfo; } catch { this.senRegeditID.Enabled = false; this.GetId.Enabled = true; } return ""; }
//加密 static public string Encrypt(string PlainText) { string KEY_64 = "dafei250"; string IV_64 = "DAFEI500"; byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = cryptoProvider.KeySize; MemoryStream ms = new MemoryStream(); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(cst); sw.Write(PlainText); sw.Flush(); cst.FlushFinalBlock(); sw.Flush(); return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); }
//解密 public static string Decrypt(string CypherText) { string KEY_64 = "haeren55"; //必須是8個字符(64Bit) string IV_64 = "HAEREN55"; //必須8個字符(64Bit) try { byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64); byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64); byte[] byEnc; try { byEnc = Convert.FromBase64String(CypherText); } catch { return null; } DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); MemoryStream ms = new MemoryStream(byEnc); CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read); StreamReader sr = new StreamReader(cst); return sr.ReadToEnd(); } catch { return "無法解密!"; } }
上述就是小編為大家分享的利用C#怎么獲取硬盤和CPU信息了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。