Obtain the cpu id and the serial number of the hard disk.

Source: Internet
Author: User
Tags emit

1. Obtain the CPU ID

DWORD cdlgregister: getcpuid () <br/>{< br/> DWORD dwid1, dwid2, dwid3, dwid4; <br/> char szcompany [13]; <br/> pchar pcompany = szcompany; </P> <p> // DWORD dwcpu; </P> <p> szcompany [12] = 0; <br/> _ ASM <br/> {<br/> pushfd <br/> pushad <br/> // obtain the ID of the CPU <br/> mov eax, 1 // function no. <br/> _ emit 0x0f <br/> _ emit 0xa2 <br/> mov dwid1, eax <br/> mov dwid2, EBX <br/> mov dwid3, ECx <br/> mov dwid4, EDX </P> <p> // obtain the name of the CPU manufacturer <br/> mov EDI, pcompany // function no. <br/> mov eax, 0 <br/> _ emit 0x0f <br/> _ emit 0xa2 <br/> mov eax, EBX <br/> stosd <br/> mov eax, EDX <br/> stosd <br/> mov eax, ECX <br/> stosd <br/> popad <br/> popfd <br/>}</P> <p> DWORD dwresult = 0; <br/> DWORD dwtemp1 = dwid1 <12; <br/> DWORD dwtemp2 = dwid2 <8; <br/> DWORD dwtemp3 = dwid3 <4; </P> <p> dwresult = dwtemp1 + dwtemp2 + dwtemp3 + dwid4; </P> <p> return dwresult; <br/>}

2. Obtain the serial number of the hard drive C.

DWORD cdlgregister: getharddisknum () <br/>{< br/> char cvolume [256]; // <br/> char cfilesysname [256]; <br/> DWORD dwserialnum; // hard disk serial number <br/> DWORD dwfilenamelength; <br/> DWORD dwfilesysflag; </P> <p >:: getvolumeinformation ("C: // ", cvolume, 256, & dwserialnum, & dwfilenamelength, <br/> & dwfilesysflag, cfilesysname, 256); </P> <p> return dwserialnum; <br/>}

 

Code for getting CPU information:

# Include "windows. H "<br/> # include" iostream "<br/> # include" string "</P> <p> using namespace STD; </P> <p> // used to store information <br/> DWORD deax; <br/> DWORD Debx; <br/> DWORD decx; <br/> DWORD dedx; </P> <p> void execpuid (DWORD veax) // initialize the CPU <br/>{< br/>__ ASM <br/>{< br/> mov eax, veax <br/> cpuid <br/> mov deax, eax <br/> mov Debx, EBX <br/> mov decx, ECx <br/> mov dedx, edX <br/>}</P> <p> long getcpufreq () // obtain the CPU frequency. Unit: MHz <br/>{< br/> int start1, start2; <br/> _ ASM rdtsc <br/> _ ASM mov start1, eax <br/> sleep (50); <br/> _ ASM rdtsc <br/> _ ASM mov start2, eax <br/> return (start2-start1)/50000; <br/>}</P> <p> string getmanid () // obtain manufacturer information <br/> {<br/> char ID [25]; // store manufacturer information <br/> memset (ID, 0, sizeof (ID); // clear the array ID first <br/> execpuid (0 ); // initialization <br/> memcpy (ID + 0, & Debx, 4); // copy the first four characters of the manufacturer information to the array <br/> memcpy (ID + 4, & dedx, 4); // four in the middle <br/> memcpy (ID + 8, & decx, 4 ); // The last four <br/> // If char * is returned, garbled characters are returned. Therefore, the return string value <br/> return string (ID ); <br/>}</P> <p> string getcputype () <br/>{< br/> const DWORD id = 0x80000002; // starting from 0x80000002, end at 0x80000004 <br/> char cputype [49]; // used to store CPU Model Information <br/> memset (cputype, 0, sizeof (cputype )); // initialize the array </P> <p> for (dword t = 0; t <3; t ++) <br/>{< br/> execpuid (ID + T); <br/> // The end of each loop, save information to the array <br/> memcpy (cputype + 16 * t + 0, & deax, 4); <br/> memcpy (cputype + 16 * t + 4, & Debx, 4); <br/> memcpy (cputype + 16 * t + 8, & decx, 4); <br/> memcpy (cputype + 16 * t + 12, & dedx, 4); <br/>}</P> <p> return string (cputype); <br/>}</P> <p> void main () <br/>{< br/> cout <"the CPU information of the local machine is as follows:" <Endl; <br/> cout <"CPU master frequency: "<getcpufreq () <" MHz "<Endl; <br/> cout <" CPU manufacturer: "<getmanid () <Endl; <br/> cout <"cpu id:" <getcputype () <Endl; <br/> cin. get (); </P> <p >}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.