⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_unit.cpp

📁 如何获取cpu 内存 硬盘等物理硬件序列号
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Main_Unit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainFrm *MainFrm;
HINSTANCE ins;
FARPROC procCPU,procDisk;
typedef char * (__stdcall *TGetStrFun)(LPCSTR);
typedef void (__stdcall *TDes)(char*,char*,char*,int);

TGetStrFun procMD5,procSN;
TDes procDes;
//---------------------------------------------------------------------------
__fastcall TMainFrm::TMainFrm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainFrm::pnlTitleMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    // 移动没有标题栏的窗体
    Refresh();
    if(Button == mbLeft)
    {
        ReleaseCapture();
        Perform(WM_SYSCOMMAND, 0xF017, 0);
    }
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::btnMenuUpDownClick(TObject *Sender)
{
    if(btnMenuUpDown->Caption == "6")
    {
        // 还原窗体
        btnMenuUpDown->Caption = "5";
        Height = 350;
    }
    else
    {
        // 上卷窗体
        btnMenuUpDown->Caption = "6";
        Height = 25;
    }
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::imgLogoMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  ShellExecute(Handle, NULL, "http://zydlm.wxhc.com.cn", NULL, NULL, SW_SHOWNORMAL);        
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::btnMenuCloseClick(TObject *Sender)
{
  Close();        
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::FormCreate(TObject *Sender)
{
  ins=LoadLibrary("Reg.dll");
  if (ins!=NULL)
    btnGet->Enabled =true;
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::btnGetClick(TObject *Sender)
{
  if (ins!=NULL)
  {
    //取硬盘序列号的函数
    procDisk=GetProcAddress(ins,"ReadPhysicalDrive");

    //取CPU序列号的函数
    procCPU=GetProcAddress(ins,"GetCPUID");

    //得到DES函数的函数
    procDes=(TDes)GetProcAddress(ins,"Des");

    //得到MD5函数的函数
    procMD5=(TGetStrFun)GetProcAddress(ins,"GetMD5Str");

    //产生序列号
    procSN=(TGetStrFun)GetProcAddress(ins,"CreateSerialNumber");

    if ((procDisk)&&(procDes)&&(procCPU)&&(procMD5))
    {
      char *p;
      char buf[128];

      //取硬盘序列号
      p=(char*)procDisk();
      edtDiskID->Text=p;

      edtDiskDes->Text=procMD5(edtDiskID->Text.c_str());
//      procDes(p,buf,"2004",0);
//      edtDiskDes->Text=buf;

      //取CPU序列号
      p=(char*)procCPU();
      edtCPU->Text=p;

      edtCPUDes->Text=procMD5(edtCPU->Text.c_str());
//      procDes(p,buf,"2004",0);
//      edtCPUDes->Text=buf;

//      edtCode->Text=edtDiskID->Text+"-"+edtCPU->Text;
      btnCount->Enabled =true;
      btnCount->Visible =true;
    }
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::FormDestroy(TObject *Sender)
{
  FreeLibrary(ins);        
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::btnCountClick(TObject *Sender)
{
  if (ins!=NULL)
  {
    procMD5=(TGetStrFun)GetProcAddress(ins,"CreateSerialNumber");
    if (procMD5!=NULL)
    {
      char *p;
      p=(char*)procMD5(edtCode->Text.c_str());
      edtSN->Text=p;
    }
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainFrm::edtCodeChange(TObject *Sender)
{
  btnCountClick(NULL);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -