请问使用VC如何在WIN2K下读取主板的序列号。不是BIOS名称和日期,是串号。

解决方案 »

  1.   

    // ReadBiosIdClass.h: interface for the CReadBiosIdClass class.
    //
    //////////////////////////////////////////////////////////////////////#if !defined(AFX_READBIOSIDCLASS_H__70BE242F_AA8A_4E12_9F03_80EF82BD053D__INCLUDED_)
    #define AFX_READBIOSIDCLASS_H__70BE242F_AA8A_4E12_9F03_80EF82BD053D__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#define PAGE_NOACCESS 0x01 // winnt
    #define PAGE_READONLY 0x02 // winnt
    #define PAGE_READWRITE 0x04 // winnt
    #define PAGE_WRITECOPY 0x08 // winnt
    #define PAGE_EXECUTE 0x10 // winnt
    #define PAGE_EXECUTE_READ 0x20 // winnt
    #define PAGE_EXECUTE_READWRITE 0x40 // winnt
    #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
    #define PAGE_GUARD 0x100 // winnt
    #define PAGE_NOCACHE 0x200 // winnt
    typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; // windbgkd
    typedef LONG NTSTATUS;
    #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)typedef struct _UNICODE_STRING
    {
        USHORT Length;
        USHORT MaximumLength;
    #ifdef MIDL_PASS
        [size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
    #else // MIDL_PASS
        PWSTR Buffer;
    #endif // MIDL_PASS
    } UNICODE_STRING;typedef UNICODE_STRING *PUNICODE_STRING;typedef enum _SECTION_INHERIT
    {
        ViewShare = 1,
        ViewUnmap = 2
    } SECTION_INHERIT;#define OBJ_INHERIT 0x00000002L
    #define OBJ_PERMANENT 0x00000010L
    #define OBJ_EXCLUSIVE 0x00000020L
    #define OBJ_CASE_INSENSITIVE 0x00000040L
    #define OBJ_OPENIF 0x00000080L
    #define OBJ_OPENLINK 0x00000100L
    #define OBJ_VALID_ATTRIBUTES 0x000001F2Ltypedef struct _OBJECT_ATTRIBUTES
    {
        ULONG Length;
        HANDLE RootDirectory;
        PUNICODE_STRING ObjectName;
        ULONG Attributes;
        PVOID SecurityDescriptor; // Points to type SECURITY_DESCRIPTOR
        PVOID SecurityQualityOfService; // Points to type SECURITY_QUALITY_OF_SERVICE
    } OBJECT_ATTRIBUTES;typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
    #define InitializeObjectAttributes( p, n, a, r, s ) { \
    (p)->Length = sizeof( OBJECT_ATTRIBUTES ); \
    (p)->RootDirectory = r; \
    (p)->Attributes = a; \
    (p)->ObjectName = n; \
    (p)->SecurityDescriptor = s; \
    (p)->SecurityQualityOfService = NULL; \
    }class CReadBiosIdClass  
    {
    public:
    void PrintError( char *message, NTSTATUS status );
    BOOL LocateNtdllEntryPoints();
    HANDLE OpenPhysicalMemory();
    BOOL MapPhysicalMemory( HANDLE PhysicalMemory,PDWORD Address, PDWORD Length,PDWORD VirtualAddress );
    VOID UnmapPhysicalMemory( DWORD Address );
    int biosCheckAMI(DWORD Add);
    int biosCheckPhoenix(DWORD Add);
    int biosCheckAward(DWORD Add);
    CReadBiosIdClass();
    virtual ~CReadBiosIdClass();};#endif // !defined(AFX_READBIOSIDCLASS_H__70BE242F_AA8A_4E12_9F03_80EF82BD053D__INCLUDED_)
      

  2.   

    // ReadBiosIdClass.cpp: implementation of the CReadBiosIdClass class.
    //
    //////////////////////////////////////////////////////////////////////#include "stdafx.h"
    #include "ReadBiosIdClass.h"#ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endif//////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    //
    #define BYTESPERLINE 16
    //
    // Lines to print before pause
    //
    #define LINESPERSCREEN 25
    NTSTATUS (__stdcall *NtUnmapViewOfSection)
    (
        IN HANDLE ProcessHandle,
        IN PVOID BaseAddress
    );
    NTSTATUS (__stdcall *NtOpenSection)
    (
        OUT PHANDLE SectionHandle,
        IN ACCESS_MASK DesiredAccess,
        IN POBJECT_ATTRIBUTES ObjectAttributes
    );
    NTSTATUS (__stdcall *NtMapViewOfSection)
    (
        IN HANDLE SectionHandle,
        IN HANDLE ProcessHandle,
        IN OUT PVOID *BaseAddress,
        IN ULONG ZeroBits,
        IN ULONG CommitSize,
        IN OUT PLARGE_INTEGER SectionOffset, /* optional */
        IN OUT PULONG ViewSize,
        IN SECTION_INHERIT InheritDisposition,
        IN ULONG AllocationType,
        IN ULONG Protect
    );
    VOID (__stdcall *RtlInitUnicodeString)
    (
        IN OUT PUNICODE_STRING DestinationString,
        IN PCWSTR SourceString
    );
    ULONG (__stdcall *RtlNtStatusToDosError)
    (
        IN NTSTATUS Status
    );CReadBiosIdClass::CReadBiosIdClass()
    {}CReadBiosIdClass::~CReadBiosIdClass()
    {}int CReadBiosIdClass::biosCheckAward(DWORD Add)
    {
    //Example
    //AWard:07/08/2002-i845G-ITE8712-JF69VD0CC-00 
    // 10/10/98-xxx……
    //Phoenix-Award:03/12/2002-sis645-p4s333
    if(*(PUCHAR)(Add+2)=='/' && *(PUCHAR)(Add+5)=='/'){
    CHAR *p=(CHAR*)Add;
    while(*p){
    if(*p < 0x20 || *p > 0x71)
    goto NOT_AWARD;
    p++;
    }
    return 1;            

    }NOT_AWARD:
    return 0;
    }int CReadBiosIdClass::biosCheckPhoenix(DWORD Add)
    {
    //Example
    //Phoenix:NITELT0.86B.0044.P11.9910111055 
    if(*(PUCHAR)(Add+7)=='.' && *(PUCHAR)(Add+11)=='.'){
    CHAR *p=(PCHAR)Add;
    while(*p){
    if(*p < 0x20 || *p > 0x71)
    goto NOT_PHOENIX;
    p++;
    }
    return 1;            
    }
    NOT_PHOENIX:
    return 0;
    }int CReadBiosIdClass::biosCheckAMI(DWORD Add)
    {
    //Example
    //AMI:51-2300-000000-00101111-030199-
    if(*(PUCHAR)(Add+2)=='-' && *(PUCHAR)(Add+7)=='-'){
    CHAR *p=(PCHAR)Add;
    while(*p){
    if(*p < 0x20 || *p > 0x71)
    goto NOT_AMI;
    p++;
    }
    return 1;             }
    NOT_AMI:
    return 0;
    }VOID CReadBiosIdClass::UnmapPhysicalMemory(DWORD Address)
    {
        NTSTATUS status;
        status = NtUnmapViewOfSection( (HANDLE) -1, (PVOID) Address );
        if( !NT_SUCCESS(status))
        {
            PrintError("Unable to unmap view", status );
        }
    }BOOL CReadBiosIdClass::MapPhysicalMemory(HANDLE PhysicalMemory, PDWORD Address, PDWORD Length, PDWORD VirtualAddress)
    {
        NTSTATUS ntStatus;
        PHYSICAL_ADDRESS viewBase;
        char error[256];
        *VirtualAddress = 0;
        viewBase.QuadPart = (ULONGLONG) (*Address);
        ntStatus = NtMapViewOfSection (PhysicalMemory,
            (HANDLE) -1,
            (PVOID *) VirtualAddress,
            0L,
            *Length,
            &viewBase,
            Length,
            ViewShare,
            0,
            PAGE_READONLY );
        if( !NT_SUCCESS( ntStatus ))
        {
            sprintf( error, "Could not map view of %X length %X",
    *Address, *Length );
            PrintError( error, ntStatus );
            return FALSE;
        }
        *Address = viewBase.LowPart;
        return TRUE;
    }HANDLE CReadBiosIdClass::OpenPhysicalMemory()
    {
        NTSTATUS status;
        HANDLE physmem;
        UNICODE_STRING physmemString;
        OBJECT_ATTRIBUTES attributes;
        WCHAR physmemName[] = L"\\device\\physicalmemory";
        RtlInitUnicodeString( &physmemString, physmemName );
        InitializeObjectAttributes( &attributes, &physmemString,
        OBJ_CASE_INSENSITIVE, NULL, NULL );
        status = NtOpenSection( &physmem, SECTION_MAP_READ, &attributes );
        if( !NT_SUCCESS( status ))
        {
            PrintError( "Could not open \\device\\physicalmemory", status );
            return NULL;
        }
        return physmem;
    }BOOL CReadBiosIdClass::LocateNtdllEntryPoints()
    {
       if( !(RtlInitUnicodeString = (void (__stdcall *)(PUNICODE_STRING,PCWSTR)) GetProcAddress( GetModuleHandle("ntdll.dll"),"RtlInitUnicodeString" )) )
        {
            return FALSE;
        }
        if( !(NtUnmapViewOfSection = (NTSTATUS (__stdcall *)(HANDLE,PVOID)) GetProcAddress( GetModuleHandle("ntdll.dll"),"NtUnmapViewOfSection" )) )
        {
            return FALSE;
        }
        if( !(NtOpenSection = (NTSTATUS (__stdcall *)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES)) GetProcAddress( GetModuleHandle("ntdll.dll"),"NtOpenSection" )) )
        {
            return FALSE;
        }
        if( !(NtMapViewOfSection = (NTSTATUS (__stdcall *)(IN HANDLE,
                                                           IN HANDLE,
                                                           IN OUT PVOID *,
                                                           IN ULONG ,
                                                           IN ULONG ,
                                                           IN OUT PLARGE_INTEGER ,
                                                           IN OUT PULONG,
                                                           IN SECTION_INHERIT ,
                                                           IN ULONG ,
                                                           IN ULONG )) GetProcAddress( GetModuleHandle("ntdll.dll"),"NtMapViewOfSection" )) )
        {
            return FALSE;
        }
        if( !(RtlNtStatusToDosError = (ULONG (__stdcall *)(NTSTATUS)) GetProcAddress( GetModuleHandle("ntdll.dll"),"RtlNtStatusToDosError" )) )
        {
            return FALSE;
        }
        return TRUE;
    }void CReadBiosIdClass::PrintError(char *message, NTSTATUS status)
    {
        char *errMsg;
        FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    NULL, RtlNtStatusToDosError( status ),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    (LPTSTR) &errMsg, 0, NULL );
    TCHAR errMessage[MAX_PATH];
    sprintf(errMessage, _T("%s: %s"), message, errMsg);
        //printf("",  );
        LocalFree( errMsg );
    AfxMessageBox(errMessage);
    }
      

  3.   

    调用方法:
    #include "ReadBiosIdClass.h"......CReadBiosIdClass ReadBiosIdClass;
    ......CString GetBiosId()
    {
        HANDLE physmem;
        DWORD vaddress, paddress;
    DWORD length=1; CString strId;    char ch;
          if(!ReadBiosIdClass.LocateNtdllEntryPoints())
        {
            AfxMessageBox("Unable to locate NTDLL entry points!");
            return -1;
        }
        //
        // Open physical memory
        //
        if( !(physmem = ReadBiosIdClass.OpenPhysicalMemory()))
        {
            return -1;
        } int i=0;
    paddress=0x000fec71;//Award
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000fec71-0x000fe000;    if(ReadBiosIdClass.biosCheckAward(vaddress+paddress))
    {
    strId = _T("Is Award Bios!    ");
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);        
    }
    else
    {
    //printf("\r\n");
    break;
    }
    i++;
    }
    } paddress=0x000ff478;//AMI
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000ff478-0x000ff000;    if(ReadBiosIdClass.biosCheckAMI(vaddress+paddress))
    {
    strId = _T("Is AMI Bios!    ");
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);        
    }
    else
    {
    //printf("\r\n");
    break;
    }
    i++;
    }
    }  paddress=0x000ff478;//AMI
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000ff478-0x000ff000;    if(ReadBiosIdClass.biosCheckAMI(vaddress+paddress))
    {
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);
    }
    else
    {
    printf("\r\n");
    break;

    }
    i++;
    }
    }

    paddress=0x000f6577;//Phoenix
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000f6577-0x000f6000;    if(ReadBiosIdClass.biosCheckPhoenix(vaddress+paddress))
    {
    strId = _T("Is Phoenix Bios!    ");
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);
      }
    else
    {
    //printf("\r\n");
    break;
    }
    i++;
    }
    }

    paddress=0x000f7196;//Phoenix
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000f7196-0x000f7000;    if(ReadBiosIdClass.biosCheckPhoenix(vaddress+paddress))
    {
    strId = _T("Is Phoenix Bios!    ");
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);        
    }
    else
    {
    //printf("\r\n");
    break;
    }
    i++;
    }
    }
    paddress=0x000f7550;//Phoenix
    ReadBiosIdClass.MapPhysicalMemory( physmem, &paddress, &length,&vaddress ) ;
    paddress=0x000f7550-0x000f7000;    if(ReadBiosIdClass.biosCheckPhoenix(vaddress+paddress))
    {
    strId = _T("Is Phoenix Bios!    ");
    while(i<50)
    {
    if(*(PUCHAR)(vaddress+paddress+i) > 0x20 && *(PUCHAR)(vaddress+paddress+i) < 0x71)
    {
    ch = *(PCHAR)(vaddress+paddress+i);
    strId = strId + ch;
    //printf("%c", ch);
    }
    else
    {
    //printf("\r\n");
    break;
    }
    i++;
    }
    }
    CloseHandle(physmem);
    return strId; 
    }......
    CString strBiosId = GetBiosId();
    AfxMessageBox(strBiosId);
      

  4.   

    TO taianmonkey
    你读出来的是BIOS名称和日期,人家要的是串号撒,什么是串号,我现在都不明白BIOS内存区好像没有这东东
      

  5.   

    FEC71H地址就是主板的序列号
    你可以在Windows下进入console用debug看。要是读取这个地址的话,可以用这个方法:
    http://www.sysinternals.com/ntw2k/info/tips.shtml#kmem
    就是那个physmem程序
      

  6.   

    http://www.csdn.net/cnshare/soft/9/9091.shtm
    免费的读取主板、CPU序列号控件(代原码)(1.0)