如何在Dos下读取主板的序列号.C语言或汇编
1个回答
展开全部
抄 呵呵 来的,你研究一下
#include "stdafx.h"
#if !defined(AFX_DD71A3C0_A52F_4C38_B062_8E05785607DC__INCLUDED_)
#define AFX_DD71A3C0_A52F_4C38_B062_8E05785607DC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream>
#include <string>
#include <windows.h>
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;
}
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());
bret = TRUE;
END:
CloseHandle(hWritePipe);
CloseHandle(hReadPipe);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return(bret);
}
#include "stdafx.h"
#if !defined(AFX_DD71A3C0_A52F_4C38_B062_8E05785607DC__INCLUDED_)
#define AFX_DD71A3C0_A52F_4C38_B062_8E05785607DC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream>
#include <string>
#include <windows.h>
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;
}
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());
bret = TRUE;
END:
CloseHandle(hWritePipe);
CloseHandle(hReadPipe);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return(bret);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询