获取硬盘序列号,机器码
NET获取硬盘序列号的几个方法
最近作软件注册,收集了很多.NET相关的获取硬盘物理序列号的方法,主要分为使用WMI方式和API方式。
但这些方法均可能有问题。
1,使用WMI方式,有的机器根本取不到硬盘序列号,有的方式在Vista下面会报错。
常用的使用WMI的方式主要有下面一些方式:class HardDrive{private string model = null;private string type = null;private string serialNo = null;public string Model{get {return model;}set {model = value;}}public string Type{get {return type;}set {type = value;}}public string SerialNo{get {return serialNo;}set {serialNo = value;}}}class TestProgram{/// <summary>/// The main entry point for the application./// </summary>[STAThread]static void Main(string[] args){//在Vista下面失败ArrayList hdCollection = new ArrayList();ManagementObjectSearcher searcher = newManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");foreach(ManagementObject wmi_HD in searcher.Get()){HardDrive hd = new HardDrive();hd.Model = wmi_HD["Model"].ToString();hd.Type = wmi_HD["InterfaceType"].ToString();hdCollection.Add(hd);}searcher = newManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");int i = 0;foreach(ManagementObject wmi_HD in searcher.Get()){// get the hard drive from collection// using indexHardDrive hd = (HardDrive)hdCollection[i];// get the hardware serial no.if (wmi_HD["SerialNumber"] == null)hd.SerialNo = "None";elsehd.SerialNo = wmi_HD["SerialNumber"].ToString();++i;}// Display available hard drivesforeach(HardDrive hd in hdCollection){Console.WriteLine("Model\t\t: " + hd.Model);Console.WriteLine("Type\t\t: " + hd.Type);Console.WriteLine("Serial No.\t: " + hd.SerialNo);Console.WriteLine();}// Pause applicationConsole.WriteLine("Press [Enter] to exit...");Console.ReadLine();}}上面的方式先查询Win32_DiskDrive,然后再查询 Win32_PhysicalMedia,经过测试,这种方式不能保证在所有机器上均取得硬盘序列号,而且在Vista下面还会出错,程序直接抛出无法处理的异常。
机器码获取生成注册码
机器码获取生成注册码通过获取硬盘的物理序列号和网卡MAC地址,为您的程序提供了获取唯一的机器码,你可以根据此码,生成自己产品注册码,有效防止软件的盗版可以自己根据获取到的硬盘序列号和网卡MAC地址进行一定的加密算法生成,唯一的机器码.给自己的软件制作注册码.从今天起,您开发的的任何软件如果您愿意都可以为之加密 --为您的软件制作一款注册机!当您看完这篇文章时, 您就可以理直气壮的告诉您的用户 : "喂, 想用我的软件是吧 ? 掏钱!". 呵呵, 这当然只是给自己壮胆的话, 现在连万能注册机都有了, 人家还怕啥 ? 不过只要您想想微软, 人家再牛B的加密技术都会被国人"鄙视"? 但人家不也在中国大把大把的捞钱吗?OK, 不扯了, 我们进入正题.同一般的软件注册一样, 我们这里的注册是这样进行的:1. 首先根据用户的硬件信息生成24位的机器码-- 相当于种子,用于生成随机数2. 采用注册机根据特征数字生成一个24位注册码-- 相当于伪随机数生成器, 输出长度自己定, 最后用一个格式化函数,将随机数映射到ASCII字符集合3. 用户输入注册码注册成功假设客户很喜欢您的软件, 也假设他没有破解, 他需要通过以下方式向您取得注册码:(1).如果他能上网, 他需要把机器码用Email发给您;(2).如果他不能上网, 他可以把机器码用手机短信的方式发给您.(3).如果他没有手机, 他可以带着机器码然后坐火车到您的办公室想您要一个注册码. --第3条只是为了让您看帖子的时候别太枯燥了, 抱歉. 现在, 您拿到了客户的机器码后, 如果您同时也收到了他汇的钱, 呵呵, 好像给软件加密就是为了要钱吧? 那么您就可以用客户的机器码生成一个唯一的注册码再用同样的方式给用户, 最后, 用户输入注册码即可! 需要强调的是客户机器的硬件信息获取方式是有很多种选择的.这里我们选择最放心的两个硬件: CUP的序列号和硬盘的卷标号. 好了,下面您就可以一步一步制作一款软件注册机了. 步骤一: 获得CUP序列号和硬盘序列号的实现代码如下:Java代码#region 获取cpu的序列号public string getCpu(){string strCpu = null;ManagementClass myCpu = newManagementClass("win32_Processor");ManagementObjectCollection myCpuConnection = myCpu.GetInstances();foreach( ManagementObject myObject in myCpuConnection){strCpu =myObject.Properties["Processorid"].Value.ToString();break;}return strCpu;}#endregion#region 获取cpu的序列号public string getCpu(){string strCpu = null;ManagementClass myCpu = newManagementClass("win32_Processor");ManagementObjectCollection myCpuConnection = myCpu.GetInstances();foreach( ManagementObject myObject in myCpuConnection){strCpu =myObject.Properties["Processorid"].Value.ToString();break;}return strCpu;}#endregionJava代码#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString(); }#endregion#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = newManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString();}#endregion步骤二: 收集硬件信息生成机器码, 代码如下:Java代码private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}步骤三: 使用机器码生成软件注册码, 代码如下:Java代码public int[] intCode = new int[127];//用于存密钥public void setIntCode()//给数组赋值个小于10的随机数{Random ra = new Random();for (int i = 1; i < intCode.Length;i++ ){intCode[i] = ra.Next(0, 9);}}public int[] intNumber = new int[25];//用于存机器码的Ascii值public char[] Charcode = new char[25];//存储机器码字//生成注册码private void button2_Click(object sender, EventArgse) {if (label2.Text != ""){setIntCode();//初始化127位数组for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中{Charcode[i] =Convert.ToChar(label2.Text.Substring(i - 1,1));}//for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
C语言获得硬盘序列号
C++获取硬盘序列号#include <windows.h>#include <iostream.h>#include <stdio.h>#pragma argsused#define DFP_GET_VERSION 0x00074080#define DFP_SEND_DRIVE_COMMAND 0x0007c084#define DFP_RECEIVE_DRIVE_DA TA 0x0007c088//#pragma pack(1)typedef struct _GETVERSIONOUTPARAMS {BYTE bVersion; //Binary driver version.BYTE bRevision; //Binary driver revision.BYTE bReserved; //Not used.BYTE bIDEDeviceMap; //Bit map of IDE devices.DWORD fCapabilities; //Bit mask of driver capabilities.DWORD dwReserved[4]; //For future use.} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOU TPARAMS;typedef struct _IDEREGS {BYTE bFeaturesReg; //Used for specifying SMART "commands".BYTE bSectorCountReg; //IDE sector count registerBYTE bSectorNumberReg; //IDE sector number registerBYTE bCylLowReg; // IDE low order cylinder valueBYTE bCylHighReg; // IDE high order cylinder valueBYTE bDriveHeadReg; // IDE drive/head registerBYTE bCommandReg; // Actual IDE command.BYTE bReserved; // reserved for future use. Must be zero.} IDEREGS, *PIDEREGS, *LPIDEREGS;typedef struct _SENDCMDINPARAMS {DWORD cBufferSize; // Buffer size in bytesIDEREGS irDriveRegs; // Structure with drive register values.BYTE bDriveNumber; // Physical drive number to send// command to (0,1,2,3).BYTE bReserved[3]; // Reserved for future expansion.DWORD dwReserved[4]; // For future use.//BYTE bBuffer[1]; // Input buffer.} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;typedef struct _DRIVERSTA TUS {BYTE bDriverError; // Error code from driver,// or 0 if no error.BYTE bIDEStatus; // Contents of IDE Error register.// Only valid when bDriverError// is SMART_IDE_ERROR.BYTE bReserved[2]; // Reserved for future expansion.DWORD dwReserved[2]; // Reserved for future expansion.} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;typedef struct _SENDCMDOUTPARAMS {DWORD cBufferSize; // Size of bBuffer in bytesDRIVERSTATUS DriverStatus; // Driver status structure.BYTE bBuffer[512]; // Buffer of arbitrary length// in which to store the data read from the drive.} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAM S;typedef struct _IDSECTOR {USHORT wGenConfig;USHORT wNumCyls;USHORT wReserved;USHORT wNumHeads;USHORT wBytesPerTrack;USHORT wBytesPerSector;USHORT wSectorsPerTrack;USHORT wVendorUnique[3];CHAR sSerialNumber[20];USHORT wBufferType;USHORT wBufferSize;USHORT wECCSize;CHAR sFirmwareRev[8];CHAR sModelNumber[40];USHORT wMoreVendorUnique;USHORT wDoubleWordIO;USHORT wCapabilities;USHORT wReserved1;USHORT wPIOTiming;USHORT wDMA Timing;USHORT wBS;USHORT wNumCurrentCyls;USHORT wNumCurrentHeads;USHORT wNumCurrentSectorsPerTrack;ULONG ulCurrentSectorCapacity;USHORT wMultSectorStuff;ULONG ulTotalAddressableSectors;USHORT wSingleWordDMA;USHORT wMultiWordDMA;BYTE bReserved[128];} IDSECTOR, *PIDSECTOR;/*+++Global vars---*/GETVERSIONOUTPARAMS vers;SENDCMDINPARAMS in;SENDCMDOUTPARAMS out;HANDLE h;DWORD i;BYTE j;char HardDiskNO[200];VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize){USHORT i;CHAR temp;for (i = 0; i < uscStrSize; i+=2){temp = szString[i];szString[i] = szString[i+1];szString[i+1] = temp;}}void DetectIDE(BYTE bIDEDeviceMap){if (bIDEDeviceMap&1){if (bIDEDeviceMap&16){//cout<<"ATAPI device is attached to primary controller, drive 0."<<endl;}else{//cout<<"IDE device is attached to primary controller, drive 0."<<endl;}}if (bIDEDeviceMap&2){if (bIDEDeviceMap&32){//cout<<"ATAPI device is attached to primary controller, drive 1."<<endl;}else{//cout<<"IDE device is attached to primary controller, drive 1."<<endl;}}if (bIDEDeviceMap&4){if (bIDEDeviceMap&64){//cout<<"ATAPI device is attached to secondary controller, drive 0."<<endl;}else{//cout<<"IDE device is attached to secondary controller, drive 0."<<endl;}}if (bIDEDeviceMap&8){if (bIDEDeviceMap&128){//cout<<"ATAPI device is attached to secondary controller, drive 1."<<endl;}else{//cout<<"IDE device is attached to secondary controller, drive 1."<<endl;}}}void hdid9x(){ZeroMemory(&vers,sizeof(vers));//We start in 95/98/Meh=CreateFile("\\\\.\\Smartvsd",0,0,0,CREATE_NEW,0,0);if (!h){//cout<<"open smartvsd.vxd failed"<<endl;exit(0);}if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){ //cout<<"DeviceIoControl failed:DFP_GET_VERSION"<<endl;CloseHandle(h);return;}//If IDE identify command not supported, failsif (!(vers.fCapabilities&1)){//cout<<"Error: IDE identify command not supported.";CloseHandle(h);return;}//Display IDE drive number detectedDetectIDE(vers.bIDEDeviceMap);//Identify the IDE drivesfor (j=0;j<4;j++){PIDSECTOR phdinfo;char s[41];ZeroMemory(&in,sizeof(in));ZeroMemory(&out,sizeof(out));if (j&1){in.irDriveRegs.bDriveHeadReg=0xb0;}else{in.irDriveRegs.bDriveHeadReg=0xa0;}if (vers.fCapabilities&(16>>j)){//We don't detect a ATAPI device.//cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<end l;continue;}else{in.irDriveRegs.bCommandReg=0xec;}in.bDriveNumber=j;in.irDriveRegs.bSectorCountReg=1;in.irDriveRegs.bSectorNumberReg=1;in.cBufferSize=512;if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0 )){//cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;CloseHandle(h);return;}phdinfo=(PIDSECTOR)out.bBuffer;memcpy(s,phdinfo->sModelNumber,40);s[40]=0;ChangeByteOrder(s,40);//cout<<endl<<"Module Number:"<<s<<endl;memcpy(s,phdinfo->sFirmwareRev,8);s[8]=0;ChangeByteOrder(s,8);//cout<<"\tFirmware rev:"<<s<<endl;memcpy(s,phdinfo->sSerialNumber,20);s[20]=0;ChangeByteOrder(s,20);strcpy(HardDiskNO, s);//cout<<"\tSerial Number:"<<s<<endl;//cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;}//Close handle before quitCloseHandle(h);}void hdidnt(){char hd[80];PIDSECTOR phdinfo;char s[41];ZeroMemory(&vers,sizeof(vers));//We start in NT/Win2000for (j = 0; j < 4; j++){sprintf(hd,"\\\\.\\PhysicalDrive%d",j);h = CreateFile(hd,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);if (!h) continue;if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){CloseHandle(h);continue;}//If IDE identify command not supported, failsif (!(vers.fCapabilities&1)){CloseHandle(h);return;}//Identify the IDE drivesZeroMemory(&in,sizeof(in));ZeroMemory(&out,sizeof(out));if (j&1){in.irDriveRegs.bDriveHeadReg=0xb0;}else{in.irDriveRegs.bDriveHeadReg=0xa0;}if (vers.fCapabilities&(16>>j)) {//We don't detect a ATAPI device.//cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;continue;}else{in.irDriveRegs.bCommandReg=0xec;}in.bDriveNumber=j;in.irDriveRegs.bSectorCountReg=1;in.irDriveRegs.bSectorNumberReg=1;in.cBufferSize=512;if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DA TA,&in,sizeof(in),&out,sizeof(out),&i,0)){ //cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;CloseHandle(h);return;}phdinfo=(PIDSECTOR)out.bBuffer;memcpy(s,phdinfo->sModelNumber,40);s[40]=0;ChangeByteOrder(s,40);//cout<<endl<<"Module Number:"<<s<<endl;memcpy(s,phdinfo->sFirmwareRev,8);s[8]=0;ChangeByteOrder(s,8);//cout<<"\tFirmware rev:"<<s<<endl;memcpy(&s[21],phdinfo->sSerialNumber,20);s[40]=0;ChangeByteOrder(&s[21],20);//cout<<"\tSerial Number:"<<s<<endl;sprintf(s, "硬盘%d 的序列号是:%s", j + 1, &s[21]);strcpy(&HardDiskNO[j * 50], s);//cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;CloseHandle(h);}}extern "C" {char * _export _stdcall GetHardDiskNO();}//---------------------------------------------------------------------------char * _stdcall GetHardDiskNO(){OSVERSIONINFO VersionInfo;ZeroMemory(&VersionInfo,sizeof(VersionInfo));VersionInfo.dwOSVersionInfoSize=sizeof(VersionInfo);GetVersionEx(&VersionInfo);memset(HardDiskNO, 0, 200);switch (VersionInfo.dwPlatformId){case VER_PLATFORM_WIN32s:break;case VER_PLATFORM_WIN32_WINDOWS:hdid9x();break;case VER_PLATFORM_WIN32_NT:hdidnt();break;}return HardDiskNO;}。
硬盘序列号怎么查询
硬盘序列号怎么查询近些年由于山寨产品的涌现,严重损害了原品牌产品的声誉和口碑,也正因为如此,一些商家想到了在产品上加注防伪码和防伪标志,然后向用户提供一个网站,用户可以到这个网站根据商家提供的字符进行验明真伪。
具有防伪码的商品有很多,诸如鞋子、音响、电脑鼠标、电脑硬盘等,像鞋子的防伪码在包装盒子上就能找到,而硬盘的序列号到底在哪里查询呢。
为了确保自己电脑的硬盘是真品,店铺今天就为大家介绍一下如何查询硬盘的序列号。
硬盘是电脑主要的存储媒介之一,由一个或者多个铝制或者玻璃制的碟片组成。
碟片外覆盖有铁磁性材料。
硬盘有固态硬盘(SSD 盘,新式硬盘)、机械硬盘(HDD 传统硬盘)、混合硬盘(HHD 一块基于传统机械硬盘诞生出来的新硬盘)。
SSD采用闪存颗粒来存储,HDD采用磁性碟片来存储,混合硬盘(HHD: Hybrid Hard Disk)是把磁性硬盘和闪存集成到一起的一种硬盘。
绝大多数硬盘都是固定硬盘,被永久性地密封固定在硬盘驱动器中。
硬盘的序列号和鞋子、音响不同,它的序列号就是验证正品、山寨的防伪码,但是这个序列号又不是直接印刷在电脑硬盘本身或者盒子上的,所以要查询电脑硬盘的序列号,其步骤是这样的。
首先需要一台电脑,因为我们要查询的就是电脑硬盘的序列号,没有电脑怎么查……另外就是需要查询硬盘序列号的工具,这个工具就是一个查询软件。
用户可以在电脑百度上面输入“硬盘序列号读取工具”。
因为有很多硬盘序列号读取软件,找一款绿色免费版的是最正确的。
下载一款软件就好,下载完成之后打开,这时的硬盘序列号读取工具就相当于一款普通的应用软件,用户将软件打开之后,找到标有“硬盘序列号读取工具………应用程序”,双击打开。
之后会出现一个全新的对话框,对话框的标题是“硬盘序列号读取工具V1.0”在标题的下面有“序列号、点击按钮、读取”等操作选项。
我们是为了查询电脑硬盘的序列号,所以点击“读取”按钮,之后对话框中就会出现该电脑硬盘的序列号了,序列号的组成一般都是数字和字母混合组成。
获取硬盘序列号的代码
获取硬盘序列号的代码网上有很多获取硬盘序列号的代码,但大部分都只能取得逻辑分区的序列号,而不能取得硬盘的物理序列号。
我们知道,逻辑分区的序列号是FORMAT时产生的,重新FORMAT将会改变。
这对于要求唯一识别码的程式来说是致命的。
这段代码利用API可以取得物理硬盘的很多特性,包括硬盘出厂时的唯一编号。
这段代码我是从CSDN 论坛获得,原作者不详。
我将其稍做修改和增添,独立出两个常用的函数:GetDiskVolume 、GetHardDiskInfo ......'====================================== ======'模块功能: 取得硬盘的信息'编程:来自互联网,阿勇修改'更新日期:2005/7/8'调用方法:' GetDiskVolume() 取得逻辑盘的序列号' GetHardDiskInfo() 取得物理盘的型号或序列号'====================================== ======Private Const MAX_IDE_DRIVES As Long = 4 ' Max number of drives assuming primary/secondary, master/slave topology Private Const READ_ATTRIBUTE_BUFFER_SIZE As Long = 512 Private Const IDENTIFY_BUFFER_SIZE As Long = 512Private Const READ_THRESHOLD_BUFFER_SIZE As Long = 512Private Const DFP_GET_VERSION As Long = &H74080Private Const DFP_SEND_DRIVE_COMMAND As Long = &H7C084Private Const DFP_RECEIVE_DRIVE_DATA As Long = &H7C088Private Type GETVERSIONOUTPARAMSbVersion As Byte ' Binary driver version.bRevision As Byte ' Binary driver revision.bReserved As Byte ' Not used.bIDEDeviceMap As Byte ' Bit map of IDE devices.fCapabilities As Long ' Bit mask of driver capabilities.dwReserved(3) As Long ' For future use.End TypePrivate Const CAP_IDE_ID_FUNCTION As Long = 1 ' ATA ID command supportedPrivate Const CAP_IDE_ATAPI_ID As Long = 2 ' ATAPI ID command supportedPrivate Const CAP_IDE_EXECUTE_SMART_FUNCTION As Long = 4 ' SMART commannds supportedPrivate Type IDEREGSbFeaturesReg As Byte ' Used for specifying SMART "commands".bSectorCountReg As Byte ' IDE sector count registerbSectorNumberReg As Byte ' IDE sector number registerbCylLowReg As Byte ' IDE low order cylinder valuebCylHighReg As Byte ' IDE high order cylinder valuebDriveHeadReg As Byte ' IDE drive/head registerbCommandReg As Byte ' Actual IDE command.bReserved As Byte ' reserved for future use. Must be zero.End TypePrivate Type SENDCMDINPARAMScBufferSize As Long ' Buffer size in bytesirDriveRegs As IDEREGS ' Structure with drive register values.bDriveNumber As Byte ' Physical drive number to send' command to (0,1,2,3).bReserved(2) As Byte ' Reserved for future expansion.dwReserved(3) As Long ' For future use.bBuffer(0) As Byte ' Input buffer.End TypePrivate Const IDE_ATAPI_ID As Long = &HA1 ' Returns ID sector for ATAPI.Private Const IDE_ID_FUNCTION As Long = &HEC ' Returns ID sector for ATA.Private Const IDE_EXECUTE_SMART_FUNCTION As Long = &HB0 ' Performs SMART cmd.Private Const SMART_CYL_LOW As Long = &H4FPrivate Const SMART_CYL_HI As Long = &HC2Private Type DRIVERSTATUSbDriverError As Byte ' Error code from driver,bIDEStatus As Byte ' Contents of IDE Error register.bReserved(1) As Byte ' Reserved for future expansion.dwReserved(1) As Long ' Reserved for future expansion.End TypePrivate Const SMART_NO_ERROR As Long = 0 ' No errorPrivate Const SMART_IDE_ERROR As Long = 1 ' Error fromIDE controllerPrivate Const SMART_INVALID_FLAG As Long = 2 ' Invalid command flagPrivate Const SMART_INVALID_COMMAND As Long = 3 ' Invalid command bytePrivate Const SMART_INVALID_BUFFER As Long = 4 ' Bad buffer (null, invalid addr..)Private Const SMART_INVALID_DRIVE As Long = 5 ' Drive number not validPrivate Const SMART_INVALID_IOCTL As Long = 6 ' Invalid IOCTLPrivate Const SMART_ERROR_NO_MEM As Long = 7 ' Could not lock user's bufferPrivate Const SMART_INVALID_REGISTER As Long = 8 ' Some IDE Register not validPrivate Const SMART_NOT_SUPPORTED As Long = 9 ' Invalid cmd flag setPrivate Const SMART_NO_IDE_DEVICE As Long = 10 ' Cmd issued to device not presentPrivate Type SENDCMDOUTPARAMScBufferSize As Long ' Size of bBuffer in bytesdrvStatus As DRIVERSTATUS ' Driver status structure.bBuffer(0) As Byte ' Buffer of arbitrary length in which to store the data read from the ' drive.End TypePrivate Const SMART_READ_ATTRIBUTE_VALUES As Long = &HD0 ' ATA4: RenamedPrivate Const SMART_READ_ATTRIBUTE_THRESHOLDS AsLong = &HD1 ' Obsoleted in ATA4!Private Const SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE As Long = &HD2Private Const SMART_SAVE_ATTRIBUTE_VALUES As Long = &HD3Private Const SMART_EXECUTE_OFFLINE_IMMEDIATE As Long = &HD4 ' ATA4Private Const SMART_ENABLE_SMART_OPERATIONS As Long = &HD8Private Const SMART_DISABLE_SMART_OPERATIONS As Long = &HD9Private Const SMART_RETURN_SMART_STATUS As Long = &HDAPrivate Type DRIVEATTRIBUTEbAttrID As Byte ' Identifies which attributewStatusFlags As Integer ' see bit definitions belowbAttrValue As Byte ' Current normalized valuebWorstValue As Byte ' How bad has it ever been?bRawValue(5) As Byte ' Un-normalized valuebReserved As Byte ' ...End TypePrivate Type ATTRTHRESHOLDbAttrID As Byte ' Identifies which attributebWarrantyThreshold As Byte ' Triggering valuebReserved(9) As Byte ' ...End TypePrivate Type IDSECTORwGenConfig As IntegerwNumCyls As IntegerwReserved As IntegerwNumHeads As IntegerwBytesPerTrack As IntegerwBytesPerSector As IntegerwSectorsPerTrack As IntegerwVendorUnique(2) As IntegersSerialNumber(19) As BytewBufferType As IntegerwBufferSize As IntegerwECCSize As IntegersFirmwareRev(7) As BytesModelNumber(39) As BytewMoreVendorUnique As IntegerwDoubleWordIO As IntegerwCapabilities As IntegerwReserved1 As IntegerwPIOTiming As IntegerwDMATiming As IntegerwBS As IntegerwNumCurrentCyls As IntegerwNumCurrentHeads As IntegerwNumCurrentSectorsPerTrack As IntegerulCurrentSectorCapacity(3) As Byte '这里只能用byte,因为VB 没有无符号的LONG型变量wMultSectorStuff As IntegerulTotalAddressableSectors(3) As Byte '这里只能用byte,因为VB没有无符号的LONG型变量wSingleWordDMA As IntegerwMultiWordDMA As IntegerbReserved(127) As ByteEnd TypePrivate Const ATTR_INVALID As Long = 0Private Const ATTR_READ_ERROR_RATE As Long = 1Private Const ATTR_THROUGHPUT_PERF As Long = 2Private Const ATTR_SPIN_UP_TIME As Long = 3Private Const ATTR_START_STOP_COUNT As Long = 4Private Const ATTR_REALLOC_SECTOR_COUNT As Long = 5 Private Const ATTR_READ_CHANNEL_MARGIN As Long = 6 Private Const ATTR_SEEK_ERROR_RATE As Long = 7Private Const ATTR_SEEK_TIME_PERF As Long = 8Private Const ATTR_POWER_ON_HRS_COUNT As Long = 9 Private Const ATTR_SPIN_RETRY_COUNT As Long = 10Private Const ATTR_CALIBRATION_RETRY_COUNT As Long = 11Private Const ATTR_POWER_CYCLE_COUNT As Long = 12Private Const PRE_FAILURE_WARRANTY As Long = &H1Private Const ON_LINE_COLLECTION As Long = &H2Private Const PERFORMANCE_ATTRIBUTE As Long = &H4Private Const ERROR_RATE_ATTRIBUTE As Long = &H8Private Const EVENT_COUNT_ATTRIBUTE As Long = &H10 Private Const SELF_PRESERVING_ATTRIBUTE As Long = &H20Private Const NUM_ATTRIBUTE_STRUCTS As Long = 30Private Const INVALID_HANDLE_VALUE As Long = -1Private Const VER_PLATFORM_WIN32s As Long = 0Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1Private Const VER_PLATFORM_WIN32_NT As Long = 2Private Type OSVERSIONINFOdwOSVersionInfoSize As LongdwMajorVersion As LongdwMinorVersion As LongdwBuildNumber As LongdwPlatformId As LongszCSDVersion As String * 128 ' Maintenance string for PSS usageEnd TypePrivate Const CREATE_NEW As Long = 1Private Const GENERIC_READ As Long = &H80000000Private Const GENERIC_WRITE As Long = &H40000000Private Const FILE_SHARE_READ As Long = &H1Private Const FILE_SHARE_WRITE As Long = &H2Private Const OPEN_EXISTING As Long = 3Private m_DiskInfo As IDSECTORPrivate Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As LongPrivate Declare Function CreateFile Lib "kernel32" Alias"CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile AsLong) As LongPrivate Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long'信息类型枚举Enum eumInfoTypehdmodelsn = 0hdOnlyModel = 1hdOnlySN = 2End Enum'磁盘通道枚举Enum eumDiskNohdPrimaryMaster = 0hdPrimarySlave = 1hdSecondaryMaster = 2hdSecondarySlave = 3End Enum'取得逻辑盘序列号 (非唯一)Function GetDiskVolume(Optional ByVal strDiskName = "C") As StringDim TempStr1 As String * 256, TempStr2 As String * 256Dim TempLon1 As Long, TempLon2 As Long, GetVal As Long Dim tmpVol As StringCall GetVolumeInformation(strDiskName & ":\", TempStr1, 256, GetVal, TempLon1, TempLon2, TempStr2, 256)If GetVal = 0 ThentmpVol = ""ElsetmpVol = Hex(GetVal)tmpVol = String(8 - Len(tmpVol), "0") & tmpVoltmpVol = Left(tmpVol, 4) & "-" & Right(tmpVol, 4)End IfGetDiskVolume = tmpVolEnd Function'取得硬盘信息:型号/物理系列号(唯一)Function GetHardDiskInfo(Optional ByVal numDisk As eumDiskNo = hdPrimaryMaster, Optional ByVal numType As eumInfoType = hdOnlySN) As StringIf GetDiskInfo(numDisk) = 1 ThenDim pSerialNumber As String, pModelNumber As StringpSerialNumber = StrConv(m_DiskInfo.sSerialNumber, vbUnicode)pModelNumber = StrConv(m_DiskInfo.sModelNumber, vbUnicode)Select Case numTypeCase hdOnlyModel '仅型号GetHardDiskInfo = Trim(pModelNumber)Case hdOnlySN '仅系列号GetHardDiskInfo = Trim(pSerialNumber)Case Else '型号,系列号GetHardDiskInfo = Trim(pModelNumber) & "," & Trim(pSerialNumber)End SelectEnd IfEnd FunctionPrivate Function OpenSMART(ByVal nDrive As Byte) As Long Dim hSMARTIOCTL As LongDim hd As StringDim VersionInfo As OSVERSIONINFOhSMARTIOCTL = INVALID_HANDLE_VALUEVersionInfo.dwOSVersionInfoSize = Len(VersionInfo)GetVersionEx VersionInfoSelect Case VersionInfo.dwPlatformIdCase VER_PLATFORM_WIN32sOpenSMART = hSMARTIOCTLCase VER_PLATFORM_WIN32_WINDOWShSMARTIOCTL = CreateFile("\\.\SMARTVSD", 0, 0, 0, CREATE_NEW, 0, 0)Case VER_PLATFORM_WIN32_NTIf nDrive < MAX_IDE_DRIVES Thenhd = "\\.\PhysicalDrive" & nDrivehSMARTIOCTL = CreateFile(hd, GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)End IfEnd SelectOpenSMART = hSMARTIOCTLEnd FunctionPrivate Function DoIDENTIFY(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP() As Byte, ByVal bIDCmd As Byte, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As BooleanpSCIP.cBufferSize = IDENTIFY_BUFFER_SIZEpSCIP.irDriveRegs.bFeaturesReg = 0pSCIP.irDriveRegs.bSectorCountReg = 1pSCIP.irDriveRegs.bSectorNumberReg = 1pSCIP.irDriveRegs.bCylLowReg = 0pSCIP.irDriveRegs.bCylHighReg = 0pSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)'pSCIP.irDriveRegs.bCommandReg = bIDCmdpSCIP.bDriveNumber = bDriveNumpSCIP.cBufferSize = IDENTIFY_BUFFER_SIZEDoIDENTIFY = CBool(DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA, _pSCIP, 32, _pSCOP(0), 528, _lpcbBytesReturned, 0))End FunctionPrivate Function DoEnableSMART(ByVal hSMARTIOCTL As Long, pSCIP As SENDCMDINPARAMS, pSCOP As SENDCMDOUTPARAMS, ByVal bDriveNum As Byte, lpcbBytesReturned As Long) As BooleanpSCIP.cBufferSize = 0pSCIP.irDriveRegs.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONSpSCIP.irDriveRegs.bSectorCountReg = 1pSCIP.irDriveRegs.bSectorNumberReg = 1pSCIP.irDriveRegs.bCylLowReg = SMART_CYL_LOWpSCIP.irDriveRegs.bCylHighReg = SMART_CYL_HIpSCIP.irDriveRegs.bDriveHeadReg = &HA0 Or ((bDriveNum And 1) * 2 ^ 4)pSCIP.irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTIONpSCIP.bDriveNumber = bDriveNumDoEnableSMART = CBool(DeviceIoControl(hSMARTIOCTL, DFP_SEND_DRIVE_COMMAND, _pSCIP, LenB(pSCIP) - 1, _pSCOP, LenB(pSCOP) - 1, _lpcbBytesReturned, 0))End Function'---------------------------------------------------------------------'---------------------------------------------------------------------Private Sub ChangeByteOrder(szString() As Byte, ByVal uscStrSize As Integer)Dim i As IntegerDim bTemp As ByteFor i = 0 To uscStrSize - 1 Step 2bTemp = szString(i)szString(i) = szString(i + 1)szString(i + 1) = bTempNext iEnd SubPrivate Sub DisplayIdInfo(pids As IDSECTOR, pSCIP As SENDCMDINPARAMS, ByVal bIDCmd As Byte, ByVal bDfpDriveMap As Byte, ByVal bDriveNum As Byte)ChangeByteOrder pids.sModelNumber, UBound(pids.sModelNumber) + 1ChangeByteOrder pids.sFirmwareRev, UBound(pids.sFirmwareRev) + 1ChangeByteOrder pids.sSerialNumber, UBound(pids.sSerialNumber) + 1End SubPublic Function GetDiskInfo(ByVal nDrive As Byte) As LongDim hSMARTIOCTL As LongDim cbBytesReturned As LongDim VersionParams As GETVERSIONOUTPARAMSDim scip As SENDCMDINPARAMSDim scop() As ByteDim OutCmd As SENDCMDOUTPARAMSDim bDfpDriveMap As ByteDim bIDCmd As Byte ' IDE or ATAPI IDENTIFY cmdDim uDisk As IDSECTORm_DiskInfo = uDisk''hSMARTIOCTL = OpenSMART(nDrive)If hSMARTIOCTL <> INVALID_HANDLE_VALUE ThenCall DeviceIoControl(hSMARTIOCTL, DFP_GET_VERSION, ByVal 0, 0, VersionParams, Len(VersionParams), cbBytesReturned, 0)If Not (VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10) ThenIf DoEnableSMART(hSMARTIOCTL, scip, OutCmd, nDrive, cbBytesReturned) ThenbDfpDriveMap = bDfpDriveMap Or 2 ^ nDriveEnd IfEnd IfbIDCmd = IIf((VersionParams.bIDEDeviceMap \ 2 ^ nDrive And &H10), IDE_ATAPI_ID, IDE_ID_FUNCTION)ReDim scop(LenB(OutCmd) + IDENTIFY_BUFFER_SIZE - 1) As ByteIf DoIDENTIFY(hSMARTIOCTL, scip, scop, bIDCmd, nDrive, cbBytesReturned) ThenCopyMemory m_DiskInfo, scop(LenB(OutCmd) - 4), LenB(m_DiskInfo)Call DisplayIdInfo(m_DiskInfo, scip, bIDCmd, bDfpDriveMap, nDrive)CloseHandle hSMARTIOCTLGetDiskInfo = 1Exit Function '>---> Bottom End IfCloseHandle hSMARTIOCTL GetDiskInfo = 0Else 'NOT HSMARTIOCTL... GetDiskInfo = -1End IfEnd Function。
win10查看硬盘序列号
查看硬盘序列号
第一步:win+r
第二步:cmd
第三步:diskpart
第四步:选“是”
第五步:select disk 0
第六步:detail disk
第七步:复制序列号
第八步:粘贴序列号
查看硬盘序列号详细请看一下操作:第一步:win+r(两个键一起按)
左下角会弹出以下输入框。
第二步:输入“cmd”(在输入框内填上“cmd”三个英文字母,大小写都可以)
输入“cmd”后,按<回车(enter)键>或者鼠标点【确定】按钮。
弹出以下弹窗口。
第三步:输入“diskpart”(在光标闪烁的地方输入“diskpart”)
输入“diskpart”后,按<回车(enter)键>。
弹出如下弹窗口。
第四步:选“是”(鼠标点击“是”即可)
鼠标点击“是”后,弹出如下弹窗口。
第五步:输入命令“select disk 0”(在光标闪烁的地
方输入命令“select disk 0”,选取磁盘为0的磁盘,可以输入命令“list disk”来查看硬盘数量)
第六步:然后再输入命令“detail disk”(在光标闪烁的地方输入命令“detail disk”)
第七步:复制序列号(鼠标左键选择要复制的内容,
然后右击即可)
第八步:粘贴序列号(在记事本或者word中,ctrl+v 或者右击粘贴即可)。
westerndigital硬盘序列号
Western Digital硬盘序列号简介Western Digital是一家全球领先的硬盘制造商,其产品被广泛应用于个人电脑、移动设备和数据中心等多个领域。
为了保证硬盘的唯一性和追踪性,每个Western Digital硬盘都有一个独特的硬盘序列号。
本文将介绍Western Digital硬盘序列号的作用、如何查找和解读序列号以及常见问题的解决方案。
Western Digital硬盘序列号的作用Western Digital硬盘序列号是硬盘的唯一标识符,具有以下作用:1.唯一性:每个Western Digital硬盘的序列号都是唯一的,用于区分不同的硬盘。
这一点对于生产和追踪硬盘来说非常重要。
2.追踪性:通过硬盘序列号,可以跟踪硬盘的生产批次、出厂日期、型号等信息。
这对于售后服务、质量控制和产品回溯等方面非常有帮助。
如何查找Western Digital硬盘序列号通常,可以通过以下几种方式来查找Western Digital硬盘序列号:1.外包装盒:在购买新的Western Digital硬盘时,序列号通常会打印在硬盘的外包装盒上。
这是最常见的查找序列号的方式之一。
2.硬盘标签:每个Western Digital硬盘上都带有一个标签,上面会标明序列号、型号、容量等信息。
可以通过查看硬盘标签来找到序列号。
3.Western Digital官方工具:Western Digital官方网站提供了一些工具,可以用于查找硬盘的序列号。
例如,可以下载并安装Western Digital的硬盘检测工具,通过该工具可以查看硬盘的详细信息,包括序列号。
如何解读Western Digital硬盘序列号Western Digital硬盘序列号通常由一系列字母和数字组成。
以下是一个典型的Western Digital硬盘序列号示例:WD-WMC4E0N1HCH5解读这个序列号可以从以下几个方面入手:1.前两个字母代表厂商代码,表示硬盘的制造商是Western Digital。
机器码获取生成注册码
机器码获取生成注册码通过获取硬盘的物理序列号和网卡MAC地址,为您的程序提供了获取唯一的机器码,你可以根据此码,生成自己产品注册码,有效防止软件的盗版可以自己根据获取到的硬盘序列号和网卡MAC地址进行一定的加密算法生成,唯一的机器码.给自己的软件制作注册码.从今天起,您开发的的任何软件如果您愿意都可以为之加密 --为您的软件制作一款注册机!当您看完这篇文章时, 您就可以理直气壮的告诉您的用户 : "喂, 想用我的软件是吧 ? 掏钱!". 呵呵, 这当然只是给自己壮胆的话, 现在连万能注册机都有了, 人家还怕啥 ? 不过只要您想想微软, 人家再牛B的加密技术都会被国人"鄙视"? 但人家不也在中国大把大把的捞钱吗?OK, 不扯了, 我们进入正题.同一般的软件注册一样, 我们这里的注册是这样进行的:1. 首先根据用户的硬件信息生成24位的机器码-- 相当于种子,用于生成随机数2. 采用注册机根据特征数字生成一个24位注册码-- 相当于伪随机数生成器, 输出长度自己定, 最后用一个格式化函数,将随机数映射到ASCII字符集合3. 用户输入注册码注册成功假设客户很喜欢您的软件, 也假设他没有破解, 他需要通过以下方式向您取得注册码:(1).如果他能上网, 他需要把机器码用Email发给您;(2).如果他不能上网, 他可以把机器码用手机短信的方式发给您.(3).如果他没有手机, 他可以带着机器码然后坐火车到您的办公室想您要一个注册码. --第3条只是为了让您看帖子的时候别太枯燥了, 抱歉. 现在, 您拿到了客户的机器码后, 如果您同时也收到了他汇的钱, 呵呵, 好像给软件加密就是为了要钱吧? 那么您就可以用客户的机器码生成一个唯一的注册码再用同样的方式给用户, 最后, 用户输入注册码即可! 需要强调的是客户机器的硬件信息获取方式是有很多种选择的.这里我们选择最放心的两个硬件: CUP的序列号和硬盘的卷标号. 好了,下面您就可以一步一步制作一款软件注册机了. 步骤一: 获得CUP序列号和硬盘序列号的实现代码如下:Java代码#region 获取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;}#endregion#region 获取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;}#endregionJava代码#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString();}#endregion#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = newManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString();}#endregion步骤二: 收集硬件信息生成机器码, 代码如下:Java代码private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}步骤三: 使用机器码生成软件注册码, 代码如下:Java代码public int[] intCode = new int[127];//用于存密钥public void setIntCode()//给数组赋值个小于10的随机数{Random ra = new Random();for (int i = 1; i < intCode.Length;i++ ){intCode[i] = ra.Next(0,9);}}public int[] intNumber = new int[25];//用于存机器码的Ascii值public char[] Charcode = new char[25];//存储机器码字//生成注册码private void button2_Click(object sender, EventArgse) {if (label2.Text != ""){setIntCode();//初始化127位数组for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中{Charcode[i] =Convert.ToChar(label2.Text.Substring(i - 1,1));}//for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
计算机序列号查询方法
计算机序列号查询方法全文共四篇示例,供读者参考第一篇示例:计算机序列号是每台计算机唯一的标识符,它是由计算机制造商在生产过程中赋予计算机的,用于区分不同计算机的标识符。
计算机序列号对于计算机的管理和维护非常重要,它可以帮助我们跟踪计算机的硬件信息、保修信息等。
如果你想查询计算机的序列号,可以通过以下几种方法来实现:1.在计算机上查找序列号大多数计算机在机箱上或底部都会有一个序列号标签,你可以直接在计算机上查找这个标签,上面通常会包含计算机的序列号、型号等信息。
如果你无法找到这个标签,也可以在计算机的启动界面中查看序列号信息,不同计算机在启动界面中显示方式可能会有一些差别。
2.在操作系统中查询序列号如果你想查询计算机的序列号但是无法直接在计算机上找到标签,可以在计算机的操作系统中查找。
在Windows系统中,你可以按下Win+R组合键打开运行窗口,然后输入cmd命令打开命令提示符,输入wmic bios get serialnumber命令查看计算机的序列号。
在Mac系统中,你可以点击苹果菜单,选择“关于本机”来查看计算机的序列号。
3.使用第三方软件查询序列号如果以上两种方法都无法查询到计算机的序列号,你还可以使用一些第三方软件来帮助你查询。
有许多免费的序列号查询工具可以帮助你快速准确地查找计算机的序列号,如Belarc Advisor、SIW等等。
在查询计算机序列号时,需要注意以下几点:1.保护个人信息安全在查询计算机序列号时,需要注意保护个人信息的安全,避免将序列号泄露给不法分子造成不必要的麻烦。
2.与厂家核对信息当查询计算机序列号时,最好与计算机的厂家核对信息,确保查询到的序列号是正确的,避免因为错误的信息导致后续维护和管理问题。
3.定期备份计算机信息在查询计算机序列号的也需要定期备份计算机的重要信息,确保在计算机出现故障或丢失时可以及时恢复数据。
查询计算机序列号是计算机管理和维护工作中非常重要的一环,通过查询计算机序列号可以帮助我们更好地管理计算机的硬件信息和保修情况,提升计算机的使用效率和安全性。
通过机器码获得注册码的完整方案(转贴过来,留着看看)
通过机器码获得注册码的完整方案(转贴过来,留着看看)想加密自己的软件,看过一些软件的作法,思路如下:1、用户安装后,得出本机的机器码(硬盘的序列号,不想用网卡,因为很多机器没有网卡)。
生成机器码代码2、用户将该机器码EMAIL给我,我用该机器码生成一个注册码,发送给用户。
注册码生成代码3、用户在程序中输入该注册码,程序逆算该注册码,与机器码核对,查看是否相符。
注册码逆算、核对代码,4、如果用户安装后没有得到注册码,在N天后部分功能不可用。
不要太容易被改(虽然说安装后也只有少部份功能能用)。
时限功能代码,zw84611 (2002-12-2 23:8)function GetHDNumber(Drv : String): DWORD; //得到硬盘序列号varVolumeSerialNumber : DWORD;MaximumComponentLength : DWORD;FileSystemFlags : DWORD;beginif Drv[Length(Drv)] =':' then Drv := Drv + '\';GetVolumeInformation(pChar(Drv),nil,0,@VolumeSerialNumber,MaximumComponentLength,FileSystemFlags,nil,0);Result:= (VolumeSerialNumber);end;function Serial(Num:DWORD):string; //这个号码是用户给你生成注册码的,它通过对硬盘序列号编码而来。
var sNum:string; inChar:array[1..4]of char;beginNum:=Num xor 8009211011;sNum:=inttostr(Num);inChar[1]:=char(((integer(sNum[1])+integer(sNum[2]))mod 5)+integer('a'));inChar[2]:=char(((integer(sNum[3])+integer(sNum[4]))mod 5)+integer('a'));inChar[3]:=char(((integer(sNum[5])+integer(sNum[6]))mod 5)+integer('a'));inChar[4]:=char(((integer(sNum[7])+integer(sNum[8])+integer(sNum[9]))mod 5)+integer('a'));insert(inChar[1],sNum,1);insert(inChar[4],sNum,3);insert(inChar[2],sNum,5);insert(inChar[3],sNum,9);Result:=sNum;end;function encode(License:string):string;var str,sNum:string; number:dword; byte,byte1:array[1..4]of dword;inChar:array[1..3]of char;beginstr:=license;delete(str,1,1);delete(str,2,1);delete(str,3,1);delete(str,6,1);number:=strtoint64(str);number:=not number;number:=number xor $1973122980;byte[1]:=(number and $0ff000000) shr 24;byte[2]:=(number and $0ff0000) shr 16;byte[3]:=(number and $0ff00) shr 8;byte[4]:=(number and $0ff);byte1[1]:=((byte[1]and $0c0)+(byte[2]and $0c0)shr 2)+((byte[3]and $0c0)shr 4)+((byte[4]and $0c0)shr 6); byte1[2]:=((byte[1]and $30)shl 2)+(byte[2]and $30)+((byte[3]and $30)shr 2)+((byte[4]and $30)shr 4); byte1[3]:=((byte[1]and $0c)shl 4)+((byte[2]and $0c)shl 2)+(byte[3]and $0c)+((byte[4]and $0c)shr 2); byte1[4]:=((byte[1]and $03)shl 6)+((byte[2]and $03)shl 4)+((byte[3]and $03)shl 2)+(byte[4]and $03);number:=((byte1[1])shl 24)+((byte1[2])shl 16)+((byte1[3])shl 8)+(byte1[4]);byte[1]:=((number and $0ff000000)shr 24);//右移24位byte[2]:=((number and $0ff0000)shr 16);byte[3]:=((number and $0ff00)shr 8);byte[4]:=(number and $0ff);byte[1]:=(((byte[1] and $f0))shr 4)+(((byte[1] and $0f))shl 4);byte[2]:=(((byte[2] and $f0))shr 4)+(((byte[2] and $0f))shl 4);byte[3]:=(((byte[3] and $f0))shr 4)+(((byte[3] and $0f))shl 4);byte[4]:=(((byte[4] and $f0))shr 4)+(((byte[4] and $0f))shl 4);number:=((byte[2])shl 24)+((byte[1])shl 16)+((byte[4])shl 8)+(byte[3]);sNum:=inttostr(Number);inChar[1]:=char(((integer(sNum[1])+integer(sNum[2]))mod 5)+integer('a'));inChar[2]:=char(((integer(sNum[3])+integer(sNum[4]))mod 5)+integer('a'));inChar[3]:=char(((integer(sNum[5])+integer(sNum[6]))mod 5)+integer('a'));insert(inChar[1],sNum,1);insert(inChar[2],sNum,5);insert(inChar[3],sNum,9);result:=sNum;end;function decode(code:string):dword;var str:string; number:dword; byte,byte1:array[1..4]of dword;beginstr:=code;delete(str,1,1);delete(str,4,1);delete(str,7,1);number:= strtoint64(str);byte[1]:=(number and $0ff000000) shr 24;byte[2]:=(number and $0ff0000) shr 16;byte[3]:=(number and $0ff00) shr 8;byte[4]:=(number and $0ff);////0123 --> 1032byte[1]:=(((byte[1] and $f0))shr 4)+(((byte[1] and $0f))shl 4);byte[2]:=(((byte[2] and $f0))shr 4)+(((byte[2] and $0f))shl 4);byte[3]:=(((byte[3] and $f0))shr 4)+(((byte[3] and $0f))shl 4);byte[4]:=(((byte[4] and $f0))shr 4)+(((byte[4] and $0f))shl 4);number:=((byte[2])shl 24)+((byte[1])shl 16)+((byte[4])shl 8)+(byte[3]);byte[1]:=((number and $0ff000000)shr 24);//右移24位byte[2]:=((number and $0ff0000)shr 16);byte[3]:=((number and $0ff00)shr 8);byte[4]:=(number and $0ff);byte1[1]:=(byte[1]and $0c0)+((byte[2]and $0c0)shr 2)+((byte[3]and $0coceanwave (2002-12-3 7:28)谢先!试试看,可以后马上开贴给分。
机器码获取生成注册码
机器码获取生成注册码通过获取硬盘的物理序列号和网卡MAC地址,为您的程序提供了获取唯一的机器码,你可以根据此码,生成自己产品注册码,有效防止软件的盗版可以自己根据获取到的硬盘序列号和网卡MAC地址进行一定的加密算法生成,唯一的机器码.给自己的软件制作注册码.从今天起,您开发的的任何软件如果您愿意都可以为之加密 --为您的软件制作一款注册机!当您看完这篇文章时, 您就可以理直气壮的告诉您的用户 : "喂, 想用我的软件是吧 ? 掏钱!". 呵呵, 这当然只是给自己壮胆的话, 现在连万能注册机都有了, 人家还怕啥 ? 不过只要您想想微软, 人家再牛B的加密技术都会被国人"鄙视"? 但人家不也在中国大把大把的捞钱吗?OK, 不扯了, 我们进入正题.同一般的软件注册一样, 我们这里的注册是这样进行的:1. 首先根据用户的硬件信息生成24位的机器码-- 相当于种子,用于生成随机数2. 采用注册机根据特征数字生成一个24位注册码-- 相当于伪随机数生成器, 输出长度自己定, 最后用一个格式化函数,将随机数映射到ASCII字符集合3. 用户输入注册码注册成功假设客户很喜欢您的软件, 也假设他没有破解, 他需要通过以下方式向您取得注册码:(1).如果他能上网, 他需要把机器码用Email发给您;(2).如果他不能上网, 他可以把机器码用手机短信的方式发给您.(3).如果他没有手机, 他可以带着机器码然后坐火车到您的办公室想您要一个注册码. --第3条只是为了让您看帖子的时候别太枯燥了, 抱歉. 现在, 您拿到了客户的机器码后, 如果您同时也收到了他汇的钱, 呵呵, 好像给软件加密就是为了要钱吧? 那么您就可以用客户的机器码生成一个唯一的注册码再用同样的方式给用户, 最后, 用户输入注册码即可! 需要强调的是客户机器的硬件信息获取方式是有很多种选择的.这里我们选择最放心的两个硬件: CUP的序列号和硬盘的卷标号. 好了,下面您就可以一步一步制作一款软件注册机了. 步骤一: 获得CUP序列号和硬盘序列号的实现代码如下:Java代码#region 获取cpu的序列号public string getCpu(){string strCpu = null;ManagementClass myCpu = newManagementClass("win32_Processor");ManagementObjectCollection myCpuConnection = myCpu.GetInstances();foreach( ManagementObject myObject in myCpuConnection){strCpu =myObject.Properties["Processorid"].Value.ToString();break;}return strCpu;}#endregion#region 获取cpu的序列号public string getCpu(){string strCpu = null;ManagementClass myCpu = newManagementClass("win32_Processor");ManagementObjectCollection myCpuConnection = myCpu.GetInstances();foreach( ManagementObject myObject in myCpuConnection){strCpu =myObject.Properties["Processorid"].Value.ToString();break;}return strCpu;}#endregionJava代码#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString(); }#endregion#region 获取设备硬盘的卷标号public string GetDiskVolumeSerialNumber(){ManagementClass mc = newManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = newManagementObject("win32_logicaldisk.deviceid=\"d:\"");disk.Get();returndisk.GetPropertyValue("VolumeSerialNumber").ToString();}#endregion步骤二: 收集硬件信息生成机器码, 代码如下:Java代码private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}private void button1_Click(object sender, EventArgse) {label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号string[] strid = new string[24];for (int i = 0; i < 24; i++)//把字符赋给数组{strid[i] = label2.Text.Substring(i,1);}label2.Text = "";Random rdid = new Random();for (int i = 0; i < 24; i++)//从数组随机抽取24个字符组成新的字符生成机器三{label2.Text += strid[rdid.Next(0,24)];}}步骤三: 使用机器码生成软件注册码, 代码如下:Java代码public int[] intCode = new int[127];//用于存密钥public void setIntCode()//给数组赋值个小于10的随机数{Random ra = new Random();for (int i = 1; i < intCode.Length;i++ ){intCode[i] = ra.Next(0, 9);}}public int[] intNumber = new int[25];//用于存机器码的Ascii值public char[] Charcode = new char[25];//存储机器码字//生成注册码private void button2_Click(object sender, EventArgse) {if (label2.Text != ""){setIntCode();//初始化127位数组for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中{Charcode[i] =Convert.ToChar(label2.Text.Substring(i - 1,1));}//for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
查看计算机序列号的命令
查看计算机序列号的命令一、文档概览本文档旨在指导用户如何通过不同的命令行工具来查看计算机的序列号。
计算机序列号,又称为系统唯一识别码(System Unique Identifier, S/N),是用于标识一台计算机硬件的唯一字符串。
了解并能够检索此信息对于系统管理、硬件维护及防盗等方面至关重要。
二、准备工作在开始之前,请确保您具有管理员权限或相应权限来执行以下命令。
某些命令可能需要以管理员身份运行,以便访问系统级别的信息。
2.1 Windows 操作系统在Windows操作系统中,可以通过几种不同的方式来查看计算机序列号:2.1.1 方法一:使用系统信息命令1. 打开命令提示符(Command Prompt)。
2. 输入`wmic bios get serialnumber` 命令。
3. 按回车键执行命令。
4. 系统将返回一个包含序列号的结果。
2.1.2 方法二:使用系统管理性能工具1. 按下`Win + R` 键打开运行对话框。
2. 输入`msinfo32` 并按回车键。
3. 在打开的系统信息窗口中,查找到“系统摘要”部分。
4. 序列号通常会显示在“系统SKU编号”或“系统序列号”字段中。
2.1.3 方法三:使用第三方软件除了使用命令行工具,还可以使用第三方软件如CPU-Z、Speccy等来查看详细的硬件信息,包括序列号。
2.2 macOS 操作系统在macOS上查看序列号的方法相对简单:1. 点击苹果菜单(Apple Menu)。
2. 选择“关于本机”(About This Mac)。
3. 在打开的窗口中,点击“系统报告”(System Report)按钮。
4. 在硬件概览中可以找到序列号信息。
2.3 Linux 操作系统在Linux系统中,可以使用终端来查看序列号:2.3.1 方法一:使用dmidecode 命令1. 打开终端。
2. 输入`sudo dmidecode -s system-serial-number` 命令。
C获取电脑硬件信息(CPUID、主板ID、硬盘ID、BIOS编号)
C#获取电脑硬件信息(CPU I D、主板I D、硬盘I D、BIO S编号)最近学习过程中,想到提取系统硬件信息做一些验证,故而对网上提到的利用.NETSyste m.Man ageme nt类获取硬件信息做了进一步的学习、验证。
验证是分别在4台电脑,XPSP3系统中进行,特将验证过程记录于此。
说明:电脑1(联想品牌电脑);电脑2(HP品牌电脑);电脑3(联想品牌电脑);电脑4(兼容机);•获取CP U编号:Dim m c AsNew M anage mentC lass("Win32_Pro cesso r")D im mo c AsManag ement Objec tColl ectio n = m c.Get Insta nces()Dim strI D AsStrin g = N othin gFor Each mo A s Man ageme ntObj ect I n mocstr ID =mo.Pr opert ies("Proce ssorI d").V alue.ToStr ing()Exi t ForNexttext Box1.Text+= "C PU ID:" +strID返回结果:电脑1:CPU I D:BFE BFBFF00000F27电脑2:CPUID:BF EBFBF F00000F27电脑3:CPU ID:B FEBFB FF00000F29电脑4:CP U ID:BFEBF BFF00000F29•获取主板编号:Di m mcAs Ne w Man ageme ntCla ss("W in32_BaseB oard")Dim mocAs Ma nagem entOb jectC ollec tion= mc.GetIn stanc es()Dim s trIDAs St ring= Not hingFor E ach m o AsManag ement Objec t InmocstrID = mo.Prop ertie s("Se rialN umber").Va lue.T oStri ng()Exit ForNexttextB ox1.T ext += "主板 ID:" + st rID返回结果:电脑1:主板 ID:电脑2:主板ID:CN24401483电脑3:主板I D:AZF241001101电脑4:主板ID: •获取硬盘编号:Mana gemen tClas s mc= new Mana gemen tClas s("Wi n32_P hysic alMed ia");//网上有提到,用Win32_Di skDri ve,但是用Win32_Dis kDriv e获得的硬盘信息中并不包含Se rialN umber属性。
如何快速查看电脑硬盘序列号
如何快速查看电脑硬盘序列号?
1、点击开始,在搜索中输入cmd,回车,打开命令窗口
2、在命令行输入diskpart,启动diskpart程序,我们就是要利用这个程序来查看磁盘ID,该程序属于系统程序的一部分,大多数电脑都有的
3、启动了diskpart程序后,接着输入list disk,也就是把电脑上的所有磁盘都罗列出来,因为我的电脑上只有一个磁盘,因此就出现了磁盘0
4、接着输入select disk 0 ,也就是选择刚刚罗列出来的磁盘序号
5、选好要查看的磁盘后,接着输入detail disk,硬盘的信息将会全部展现出来,其中有一项就是磁盘ID,到此任务完成
6、然后你可以输入exit退出diskpart程序,或者直接关掉窗口就ok了,你学会了吗,现在查起磁盘ID是不是很easy?
7、。
golang获取电脑机器码的原理
golang获取电脑机器码的原理Golang获取电脑机器码的原理介绍在一些应用程序中,我们常常需要获取电脑的唯一标识码,以用于软件的授权验证、设备唯一性绑定等用途。
本文将介绍使用Golang 获取电脑机器码的原理。
什么是电脑机器码?电脑机器码是指用于唯一标识一个电脑设备的字符串或数字。
它可以包含硬件信息、操作系统信息、网络信息等。
通常情况下,电脑机器码在一台设备上是唯一的。
获取电脑机器码的方法方法一:使用WMI接口(Windows)Windows Management Instrumentation(WMI)是Windows系统提供的一种获取系统信息的接口。
我们可以使用Golang的/StackExchange/wmi库来访问WMI接口并获取电脑机器码。
以下是使用WMI接口获取电脑机器码的示例代码:package mainimport ("fmt""/StackExchange/wmi")type Win32_ComputerSystemProduct struct {UUID string}func main() {var product Win32_ComputerSystemProducterr := ("SELECT UUID FROM Win32_ComputerSystemProduc t", &product)if err == nil {("机器码:", )} else {("获取机器码失败:", err)}}方法二:使用硬件序列号一些电脑硬件设备(如CPU、主板、网卡等)上会有唯一的序列号信息。
我们可以通过读取这些硬件设备的序列号来生成电脑机器码。
以下是使用Golang获取电脑硬件序列号并生成机器码的示例代码:package mainimport ("fmt""os/exec")func runCommand(command string, args ...string) (string, error) {output, err := (command, args...).CombinedOutput() if err != nil {return "", err}return string(output), nil}func GetMachineCode() (string, error) {cpuSerial, err := runCommand("wmic", "cpu", "get", " ProcessorID")if err != nil {return "", err}mbSerial, err := runCommand("wmic", "baseboard", "ge t", "SerialNumber")if err != nil {return "", err}macAddr, err := runCommand("wmic", "nic", "get", "MA CAddress")if err != nil {return "", err}machineCode := cpuSerial + mbSerial + macAddrreturn machineCode, nil}func main() {machineCode, err := GetMachineCode()if err == nil {("机器码:", machineCode)} else {("获取机器码失败:", err)}}结论本文介绍了使用Golang获取电脑机器码的两种方法:使用WMI接口和读取硬件序列号。
API函数获取硬盘物理序列号
API函数获取硬盘物理序列号以下代码可以取得系统特征码(网卡MAC、硬盘序列号、CPU ID、BIOS编号)BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码UINT uSystemInfoLen = 0; // 在程序执行完毕后,此处存储取得的系统特征码的长度// 网卡MAC 地址,注意: MAC 地址是可以在注册表中修改的{UINT uErrorCode = 0;IP_ADAPTER_INFO iai;ULONG uSize = 0;DWORD dwResult = GetAdaptersInfo( &iai, &uSize );if( dwResult == ERROR_BUFFER_OVERFLOW ){IP_ADAPTER_INFO* piai = ( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap( ) , 0, uSize );if( piai != NULL ){dwResult = GetAdaptersInfo( piai, &uSize );if( ERROR_SUCCESS == dwResult ){IP_ADAPTER_INFO* piai2 = piai;while( piai2 != NULL && ( uSystemInfoLen + piai2->AddressLength ) < 4096U ){CopyMemory( szSystemInfo + uSystemInfoLen, piai2->Address, pi ai2->AddressLength );uSystemInfoLen += piai2->AddressLength;piai2 = piai2->Next;}}else{uErrorCode = 0xF0000000U + dwResult;}VERIFY( HeapFree( GetProcessHeap( ), 0, piai ) );}else{return FALSE;}}else{uErrorCode = 0xE0000000U + dwResult;}if( uErrorCode != 0U ){return FALSE;}}// 硬盘序列号,注意:有的硬盘没有序列号{OSVERSIONINFO ovi = { 0 };ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );GetVersionEx( &ovi );if( ovi.dwPlatformId != VER_PLATFORM_WIN32_NT ){// Only Windows 2000, Windows XP, Windows Server 2003...return FALSE;}else{if( !WinNTHDSerialNumAsPhysicalRead( szSystemInfo, &uSystemInfoLen, 1024 ) ){WinNTHDSerialNumAsScsiRead( szSystemInfo, &uSystemInfoLen, 1024 );}}}// CPU ID{BOOL bException = FALSE;BYTE szCpu[16] = { 0 };UINT uCpuID = 0U;__try{_asm{mov eax, 0cpuidmov dword ptr szCpu[0], ebxmov dword ptr szCpu[4], edxmov dword ptr szCpu[8], ecxmov eax, 1cpuidmov uCpuID, edx}}__except( EXCEPTION_EXECUTE_HANDLER ){bException = TRUE;}if( !bException ){CopyMemory( szSystemInfo + uSystemInfoLen, &uCpuID, sizeof( UINT ) );uSystemInfoLen += sizeof( UINT );uCpuID = strlen( ( char* )szCpu );CopyMemory( szSystemInfo + uSystemInfoLen, szCpu, uCpuID );uSystemInfoLen += uCpuID;}}// BIOS 编号,支持AMI, AWARD, PHOENIX{SIZE_T ssize;LARGE_INTEGER so;so.LowPart=0x000f0000;so.HighPart=0x00000000;ssize=0xffff;wchar_t strPH[30]=L"\\device\\physicalmemory";DWORD ba=0;UNICODE_STRING struniph;struniph.Buffer=strPH;struniph.Length=0x2c;struniph.MaximumLength =0x2e;OBJECT_ATTRIBUTES obj_ar;obj_ar.Attributes =64;obj_ar.Length =24;obj_ar.ObjectName=&struniph;obj_ar.RootDirectory=0;obj_ar.SecurityDescriptor=0;obj_ar.SecurityQualityOfService =0;HMODULE hinstLib = LoadLibrary("ntdll.dll");ZWOS ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection");ZWMV ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection");ZWUMV ZWunmapV=(ZWUMV)GetProcAddress(hinstLib,"ZwUnmapViewOfSection");//调用函数,对物理内存进行映射HANDLE hSection;if( 0 == ZWopenS(&hSection,4,&obj_ar) &&0 == ZWmapV(( HANDLE )hSection, //打开Section时得到的句柄( HANDLE )0xFFFFFFFF, //将要映射进程的句柄,&ba, //映射的基址0,0xFFFF, //分配的大小&so, //物理内存的地址&ssize, //指向读取内存块大小的指针1, //子进程的可继承性设定0, //分配类型2 //保护类型) )//执行后会在当前进程的空间开辟一段64k的空间,并把f000:0000到f000:ffff处的内容映射到这里//映射的基址由ba返回,如果映射不再有用,应该用ZwUnmapViewOfSection断开映射{BYTE* pBiosSerial = ( BYTE* )ba;UINT uBiosSerialLen = FindAwardBios( &pBiosSerial );if( uBiosSerialLen == 0U ){uBiosSerialLen = FindAmiBios( &pBiosSerial );if( uBiosSerialLen == 0U ){uBiosSerialLen = FindPhoenixBios( &pBiosSerial );}}if( uBiosSerialLen != 0U ){CopyMemory( szSystemInfo + uSystemInfoLen, pBiosSerial, uBiosSerialLen );uSystemInfoLen += uBiosSerialLen;}ZWunmapV( ( HANDLE )0xFFFFFFFF, ( void* )ba );}}// 完毕,系统特征码已取得。
获取硬盘序列号
用api函数读取硬盘的序列号关于盘序列号有两种:硬盘序列号: 英文名Hard Disk Serial Number, 该号是出厂时生产厂家为区别产品而设置的, 是唯一的, 是只读的, 利用硬盘序列号的加密往往是利用其唯一和只读的特性, 大多是针对有序列号的IDE HDD而言, 对于没有序列号或SCSI HDD硬盘则无能为力,这也是利用它进行加密的局限性.卷的序列号: 英文名Volume Serial Number, 该号既可指软磁盘要得, 如:A:盘和B:盘的, 又可以指硬盘的逻辑盘, 如: C:, D:...的,是高级格式化时随机产生的, 是可以修改的, 所以利用其进行加密,在写程序时我们想对每一台计算机都生成一个唯一的标识,而且在一此共享软件中我们也看到,软件在不同的机器上生成了不同的标识,这是如何实现的呢,其实是软件有一部分程序读取了,本地计算机的一部分硬件参数(如硬盘序列号,网卡序列号等等),再通过一系列算法而得到了一个唯一标识,其实我们也可以通过一个api函数生成我们的唯一标识,由于硬盘人人都有,而网卡不一定每个人都有,所以以读硬盘序列号为例,下面就先介绍一下我们要用到的api函数BOOL GetVolumeInformation(LPCTSTR lpRootPathName, // 硬盘的路径LPTSTR lpVolumeNameBuffer, // 硬盘的卷标DWORD nVolumeNameSize, // 卷标的字符串长度LPDWORD lpVolumeSerialNumber, // 硬盘的序列号LPDWORD lpMaximumComponentLength, // 最大的文件长度LPDWORD lpFileSystemFlags, // 文件系统的一此标志LPTSTR lpFileSystemNameBuffer, // 存储所在盘符的分区类型的长指针变量DWORD nFileSystemNameSize // 分区类型的长指针变量所指向的字符串长度);如果上述函数成功就返回一个非0值。
VC++获取网卡MAC、硬盘序列号、CPU+ID、BIOS编号
VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号以下代码可以取得系统特征码(网卡MAC、硬盘序列号、CPU ID、BIOS编号)BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码UINT uSystemInfoLen = 0; // 在程序执行完毕后,此处存储取得的系统特征码的长度// 网卡MAC 地址,注意: MAC 地址是可以在注册表中修改的{UINT uErrorCode=0;IP_ADAPTER_INFO iai;ULONG uSize = 0;DWORD dwResult = GetAdaptersInfo( &iai, &uSize );if( dwResult == ERROR_BUFFER_OVERFLOW ){IP_ADAPTER_INFO* piai=( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap( ), 0, uSize );if( piai != NULL ){dwResult = GetAdaptersInfo( piai, &uSize );if( ERROR_SUCCESS == dwResult ){IP_ADAPTER_INFO* piai2 = piai;while(piai2!=NULL &&(uSystemInfoLen+piai2->AddressLength )< 4096U){CopyMemory(szSystemInfo+uSystemInfoLen,piai2->Address, piai2->AddressLength );uSystemInfoLen += piai2->AddressLength;piai2 = piai2->Next;}}else{uErrorCode = 0xF0000000U + dwResult;}VERIFY( HeapFree( GetProcessHeap( ), 0, piai ) );}else{return FALSE;}}else{uErrorCode = 0xE0000000U + dwResult;}if( uErrorCode != 0U ){return FALSE;}}// 硬盘序列号,注意:有的硬盘没有序列号{OSVERSIONINFO ovi = { 0 };ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );GetVersionEx( &ovi );if( ovi.dwPlatformId != VER_PLATFORM_WIN32_NT ){// Only Windows 2000, Windows XP, Windows Server 2003...return FALSE;}else{if( !WinNTHDSerialNumAsPhysicalRead( szSystemInfo, &uSystemInfoLen, 1024 ) ){WinNTHDSerialNumAsScsiRead( szSystemInfo, &uSystemInfoLen, 1024 );}}}// CPU ID{BOOL bException = FALSE;BYTE szCpu[16] = { 0 };UINT uCpuID = 0U;__try{_asm{mov eax, 0cpuidmov dword ptr szCpu[0], ebxmov dword ptr szCpu[4], edxmov dword ptr szCpu[8], ecxmov eax, 1cpuidmov uCpuID, edx}}__except( EXCEPTION_EXECUTE_HANDLER ){bException = TRUE;}if( !bException ){CopyMemory( szSystemInfo + uSystemInfoLen, &uCpuID, sizeof( UINT ) );uSystemInfoLen += sizeof( UINT );uCpuID = strlen( ( char* )szCpu );CopyMemory( szSystemInfo + uSystemInfoLen, szCpu, uCpuID );uSystemInfoLen += uCpuID;}}// BIOS 编号,支持AMI, AW ARD, PHOENIX{SIZE_T ssize;LARGE_INTEGER so;so.LowPart=0x000f0000;so.HighPart=0x00000000;ssize=0xffff;wchar_t strPH[30]=L\\device\\physicalmemory;DWORD ba=0;UNICODE_STRING struniph;struniph.Buffer=strPH;struniph.Length=0x2c;struniph.MaximumLength =0x2e;OBJECT_ATTRIBUTES obj_ar;obj_ar.Attributes =64;obj_ar.Length =24;obj_ar.ObjectName=&struniph;obj_ar.RootDirectory=0;obj_ar.SecurityDescriptor=0;obj_ar.SecurityQualityOfService =0;HMODULE hinstLib = LoadLibrary("ntdll.dll");ZWOS ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection");ZWMV ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection");ZWUMV ZWunmapV=(ZWUMV)GetProcAddress(hinstLib,"ZwUnmapViewOfSection");//调用函数,对物理内存进行映射HANDLE hSection;if( 0 == ZWopenS(&hSection,4,&obj_ar) &&0 == ZWmapV(( HANDLE )hSection, //打开Section时得到的句柄( HANDLE )0xFFFFFFFF, //将要映射进程的句柄,&ba, //映射的基址0,0xFFFF, //分配的大小&so, //物理内存的地址&ssize, //指向读取内存块大小的指针1, //子进程的可继承性设定0, //分配类型2 //保护类型) )//执行后会在当前进程的空间开辟一段64k的空间,并把f000:0000到f000:ffff处的内容映射到这里//映射的基址由ba返回,如果映射不再有用,应该用ZwUnmapViewOfSection断开映射{BYTE* pBiosSerial = ( BYTE* )ba;UINT uBiosSerialLen = FindAwardBios( &pBiosSerial );if( uBiosSerialLen == 0U ){uBiosSerialLen = FindAmiBios( &pBiosSerial );if( uBiosSerialLen == 0U ){uBiosSerialLen = FindPhoenixBios( &pBiosSerial );}}if( uBiosSerialLen != 0U ){CopyMemory( szSystemInfo + uSystemInfoLen, pBiosSerial, uBiosSerialLen );uSystemInfoLen += uBiosSerialLen;}ZWunmapV( ( HANDLE )0xFFFFFFFF, ( void* )ba );}}// 完毕,系统特征码已取得。