?? softreg.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace VWMS.CommonClass
{
class SoftReg
{
// 取得設備硬盤的卷標號
public string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
//獲得CPU的序列號
public string getCpu()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuConnection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
break;
}
return strCpu;
}
//生成機器碼
public string getMNum()
{
string strNum = getCpu() + GetDiskVolumeSerialNumber();//獲得24位Cpu和硬盤序列號
string strMNum = strNum.Substring(0,24);//從生成的字符串中取出前24個字符做為機器碼
return strMNum;
}
public int[] intCode = new int[127];//存儲密鑰
public int[] intNumber = new int[25];//存機器碼的Ascii值
public char[] Charcode = new char[25];//存儲機器碼字
public void setIntCode()//給數組賦值小于10的數
{
for (int i = 1; i < intCode.Length; i++)
{
intCode[i] = i % 9;
}
}
//生成注冊碼
public string getRNum()
{
setIntCode();//初始化127位數組
for (int i = 1; i < Charcode.Length; i++)//把機器碼存入數組中
{
Charcode[i] = Convert.ToChar(this.getMNum().Substring(i - 1, 1));
}
for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一個整數組中。
{
intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);
}
string strAsciiName = "";//用于存儲注冊碼
for (int j = 1; j < intNumber.Length; j++)
{
if (intNumber[j] >= 48 && intNumber[j] <= 57)//判斷字符ASCII值是否0-9之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= 65 && intNumber[j] <= 90)//判斷字符ASCII值是否A-Z之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= 97 && intNumber[j] <= 122)//判斷字符ASCII值是否a-z之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else//判斷字符ASCII值不在以上范圍內
{
if (intNumber[j] > 122)//判斷字符ASCII值是否大于z
{
strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString();
}
}
}
return strAsciiName;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -