读书人

想给程序加个注册功能,哪位高手能给小

发布时间: 2012-03-16 16:34:56 作者: rapoo

想给程序加个注册功能,谁能给我读网卡真实MAC地址的代码,谢谢! - C++ Builder / Windows SDK/API
本来打算用硬盘序列号的,结果发现有些硬盘是没序列号的,又想用CUPID,结果有些CUP也没有ID,有些同一批生产的CUP的资料都一样!没办法,只能用网卡的MAC地址了,虽然MAC也能改,不过加密这东西只是防君子不防小人的.那位大侠有相应的代码就麻烦给我一下.

[解决办法]
参考:http://topic.csdn.net/u/20090211/09/121aac4a-a30b-44e5-a44e-232dfb6d5215.html
[解决办法]

Delphi(Pascal) code
function GetNetCardMac(NetCardName: string; Current: Boolean): string; inline;const  OID_802_3_PERMANENT_ADDRESS: Integer = $01010101;  OID_802_3_CURRENT_ADDRESS: Integer = $01010102;  IOCTL_NDIS_QUERY_GLOBAL_STATS: Integer = $00170002;var  hDevice: THandle;  inBuf: Integer;  outBuf: array[1..256] of Byte;  BytesReturned: DWORD;  MacAddr: string;  i: integer;begin  if Current then    inBuf  := OID_802_3_CURRENT_ADDRESS  else    inBuf  := OID_802_3_PERMANENT_ADDRESS;  hDevice := 0;  Result := '';  try    hDevice := CreateFile(PChar('\\.\' + NetCardName), GENERIC_READ or      GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);    if hDevice <> INVALID_HANDLE_VALUE then    begin      if DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, @inBuf, 4,        @outBuf, 256, BytesReturned, nil) then      begin        MacAddr := '';        for i := 1 to BytesReturned do        begin          MacAddr := MacAddr + IntToHex(outbuf[i], 2);        end;        Result := MacAddr;      end;    end;  finally    if not hDevice <> INVALID_HANDLE_VALUE then      CloseHandle(hDevice);  end;end;function GetNetCardVendor(NetCardName: string): string; inline;const  OID_GEN_VENDOR_DESCRIPTION : Integer = $0001010D;  IOCTL_NDIS_QUERY_GLOBAL_STATS: Integer = $00170002;var  hDevice: THandle;  inBuf: Integer;  outBuf: array[1..256] of AnsiChar;  BytesReturned: DWORD;begin  inBuf  := OID_GEN_VENDOR_DESCRIPTION;  hDevice := 0;  Result := '';  try    hDevice := CreateFile(PChar('\\.\' + NetCardName), GENERIC_READ or      GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);    if hDevice <> INVALID_HANDLE_VALUE then    begin      if DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, @inBuf, 4,        @outBuf, 256, BytesReturned, nil) then      Result := string(AnsiString(outBuf));    end;  finally    if not hDevice <> INVALID_HANDLE_VALUE then      CloseHandle(hDevice);  end;end;procedure TMainForm.GetMacClick(Sender: TObject);const  REG_NWC = '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards';var  NetWorkCards: TStringList;  ServiceName: string;  i: Integer;begin  Memo.Clear;  with TRegistry.Create do  begin    RootKey := HKEY_LOCAL_MACHINE;    NetWorkCards := TStringList.Create;    try      if OpenKeyReadOnly(REG_NWC) then        GetKeyNames(NetWorkCards);      for i := 0 to NetWorkCards.Count - 1 do      begin        if OpenKeyReadOnly(REG_NWC + '\' + NetWorkCards[i]) then        begin          ServiceName := ReadString('ServiceName');          Memo.Lines.Add('描述: ' + ReadString('Description'));          Memo.Lines.Add('永久地址: ' + GetNetCardMac(ServiceName, False));          Memo.Lines.Add('当前地址: ' + GetNetCardMac(ServiceName, True));          Memo.Lines.Add('厂商: ' + GetNetCardVendor(ServiceName));          Memo.Lines.Add('');          Memo.Lines.Add('');          Memo.Lines.Add('');        end;      end;    finally      NetWorkCards.Free;    end;  end;end; 

读书人网 >C++ Builder

热点推荐