get the PIII processor serial number (psn)

Posted on 2006-07-15 00:57 紫雨轩 C++ 阅读(623) 评论(0)  编辑 收藏 引用 所属分类: Win32 SDK
CString GetProcessorSeialNumbet( bool  withSeparator)
{
DWORD  t,m,b; 
// top,middle,botttom
DWORD *  serial;
  _asm
  {
    mov   eax,
1   // programmer: I need a Service ?
         
// processor: what type baby?
      
// eax = 3 --> 
       
// eax: top 32 bits are the processor signature bits
         

       
// programmer:this
    cpuid      // _emit 0x0f |cpuid mean this tow instruction
          
// _emit 0xa2 |instead of writing them 
       
//        
    
// mean:the sevice i want the processor serial number

 mov   t,eax 
//  top 32 bits are the processor signature bits
            /*  
          eax = 3 --> 
        ecx: middle 32 bits are the processor signature bits
         edx: bottom 32 bits are the processor signature bits
      
*/
    mov   eax,
3
    cpuid
    mov   m,edx
//  middle 32 bits are the processor signature bits
    mov   b,ecx //  bottom 32 bits are the processor signature bits
  }

  
//  copy the locals into the pointer variables passed in
  serial[ 0 =  b;
  serial[
1 =  m;
  serial[
2 =  t;


CString temp,SN;
SN.Empty();
static   char  hex_chars[ 16 =  { ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' ,
                 
' 8 ' , ' 9 ' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' };
for  ( int  dw_count  =   2 ; dw_count >= 0 ; dw_count -- )
  {
    
for  ( int  bp = 28 ; bp >= 0 ; bp -= 4 )
    {
      DWORD nibble 
=  (serial[dw_count]  >>  bp)  &   0x0f ;
      temp.Format(
" %c " , hex_chars[nibble]);
   SN
+= temp;
      
if  ((bp  ==   16 ||  ((bp  ==   0 &&  (dw_count != 0 )) )
    
if (withSeparator)SN += " - " ;
    }
  }
 
return  SN;
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


posts - 18, comments - 22, trackbacks - 0, articles - 7

Copyright © 紫雨轩 C++