• 大小: 9KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: 其他
  • 标签: hardware  information  

资源简介

windows下获取CPU ID,硬盘序列号,主板序列号,MAC地址等信息,配合博客https://blog.csdn.net/wolfcsharp/article/details/100984664使用

资源截图

代码片段和文件信息

//#include “stdafx.h“
#include “getbaseBoardIDByCmd.h“
 
 
//--------------------------------------------------------------
// 主板序列号 -- 获取不到时为 None
//--------------------------------------------------------------
BOOL GetbaseBoardByCmd(char *lpszbaseBoard int len/*=128*/)
{
const long MAX_COMMAND_SIZE = 10000; // 命令行输出缓冲大小
WCHAR szFetCmd[] = L“wmic baseBoard get SerialNumber“; // 获取主板序列号命令行
const string strEnSearch = “SerialNumber“; // 主板序列号的前导信息

BOOL   bret   = FALSE;
HANDLE hReadPipe  = NULL; //读取管道
HANDLE hWritePipe = NULL; //写入管道
PROCESS_INFORMATION pi;   //进程信息
STARTUPINFO si;   //控制命令行窗口信息
SECURITY_ATTRIBUTES sa;   //安全属性
 
char szBuffer[MAX_COMMAND_SIZE+1] = {0}; // 放置命令行结果的输出缓冲区
string strBuffer;
unsigned long count = 0;
long ipos  = 0;
 
memset(&pi 0 sizeof(pi));
memset(&si 0 sizeof(si));
memset(&sa 0 sizeof(sa));
 
pi.hProcess = NULL;
pi.hThread  = NULL;
si.cb = sizeof(STARTUPINFO);
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
 
//1.0 创建管道
bret = CreatePipe(&hReadPipe &hWritePipe &sa 0);
if(!bret)
{
goto END;
}
 
//2.0 设置命令行窗口的信息为指定的读写管道
GetStartupInfo(&si);
si.hStdError = hWritePipe;
si.hStdOutput = hWritePipe;
si.wShowWindow = SW_HIDE; //隐藏命令行窗口
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
 
//3.0 创建获取命令行的进程
bret = CreateProcess(NULL szFetCmd NULL NULL TRUE 0 NULL NULL &si &pi );
if(!bret)
{
goto END;
}
 
//4.0 读取返回的数据
WaitForSingleobject (pi.hProcess 500/*INFINITE*/);
bret  =  ReadFile(hReadPipe  szBuffer  MAX_COMMAND_SIZE  &count  0);
if(!bret)
{
goto END;
}
 
//5.0 查找主板序列号
bret = FALSE;
strBuffer = szBuffer;
ipos = strBuffer.find(strEnSearch);
 
if (ipos < 0) // 没有找到
{
    goto END;
}
else
{
strBuffer = strBuffer.substr(ipos+strEnSearch.length());
}
 
memset(szBuffer 0x00 sizeof(szBuffer));
strcpy_s(szBuffer strBuffer.c_str());
 
    //去掉中间的空格 \r \n
    int j = 0;
    for (int i = 0; i < strlen(szBuffer); i++)
    {
        if (szBuffer[i] != ‘ ‘ && szBuffer[i] != ‘\n‘ && szBuffer[i] != ‘\r‘)
        {
            lpszbaseBoard[j] = szBuffer[i];
            j++;
        }
    }
 
bret = TRUE;
 
END:
//关闭所有的句柄
CloseHandle(hWritePipe);
CloseHandle(hReadPipe);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
 
return(bret);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-09-30 11:04  get hardware information\
     文件        2626  2019-09-18 15:43  get hardware information\GetbaseBoardIDByCmd.cpp
     文件         574  2019-09-08 16:04  get hardware information\GetbaseBoardIDByCmd.h
     文件        2781  2019-09-08 15:32  get hardware information\GetCpuSerialByCmd.cpp
     文件         567  2019-09-08 15:32  get hardware information\GetCpuSerialByCmd.h
     文件        2790  2019-09-18 15:48  get hardware information\GetHDSerialByCmd.cpp
     文件         568  2019-09-18 15:52  get hardware information\GetHDSerialByCmd.h
     文件        2748  2019-09-18 15:43  get hardware information\GetMacIDByCmd.cpp
     文件         563  2019-09-08 15:59  get hardware information\GetMacIDByCmd.h
     文件        1781  2019-09-18 16:01  get hardware information\get_hardware_information.cpp
     文件         155  2020-09-30 11:04  get hardware information\get_hardware_information.h
     文件         181  2019-09-18 15:49  get hardware information\get_hardware_information.h.bak

评论

共有 条评论