C + + hardware information get motherboard serial number

Source: Internet
Author: User

There are many ways to get the serial number of the computer card board, which is obtained by command line , can get the motherboard serial number, very simple, directly on the code.


"1" header file

#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 & Lt;string> #include <windows.h>using namespace std;//---------------------------------------------------- ----------//Motherboard serial number//--------------------------------------------------------------BOOL getbaseboardbycmd (char * Lpszbaseboard, int len=128); #endif//!defined (AFX_DD71A3C0_A52F_4C38_B062_8E05785607DC__INCLUDED_)


"2" CPP

#include "stdafx.h" #include "BaseBoard.h"//--------------------------------------------------------------//motherboard serial number --none//--------------------------------------------------------------BOOL getbaseboardbycmd (char *) when not available Lpszbaseboard, int len/*=128*/) {Const long max_command_size = 10000;//command line output buffer size WCHAR szfetcmd[]= L "wmic baseboard get Se Rialnumber "; Get the motherboard serial number command line const string strensearch = "SerialNumber"; Leading information for motherboard serial number bool Bret = FALSE; HANDLE hreadpipe = NULL; Read pipe handle hwritepipe = NULL;   Write Pipeline process_information Pi;  Process information Startupinfosi;   Control command Line window information security_attributes sa; Security attribute Charszbuffer[max_command_size+1] = {0}; The output buffer for placing command-line results stringstrbuffer;unsigned longcount = 0;longipos = 0;memset (&pi, 0, sizeof (PI)), memset (&si, 0, si Zeof (SI)); memset (&sa, 0, sizeof (SA));p i.hprocess = Null;pi.hthread = null;si.cb= sizeof (STARTUPINFO); sa.nlength= sizeof (security_attributes); sa.lpsecuritydescriptor = null;sa.binherithandle= true;//1.0 Create pipeline bret = CreatePipe (& HreadPipe, &hwritepipe, &sa, 0); if (!bret) {goto END;} 2.0 set command-line window information for the specified read-write pipeline getstartupinfo (&si); si.hstderror= hwritepipe;si.hstdoutput= Hwritepipe;si.wshowwindow = Sw_hide; Hide command-line window si.dwflags= Startf_useshowwindow | STARTF_USESTDHANDLES;//3.0 Create a process that gets the command line bret = CreateProcess (null, szfetcmd, NULL, NULL, TRUE, 0, NULL, NULL, &AMP;SI, &p i); if (!bret) {goto END;} 4.0 read the returned data WaitForSingleObject (pi.hprocess, 500/*infinite*/); bret = ReadFile (Hreadpipe, Szbuffer, max_command_size , &count, 0); if (!bret) {goto END;} 5.0 find the motherboard serial number Bret = False;strbuffer = Szbuffer;ipos = Strbuffer.find (Strensearch); if (IPOs < 0)//not found {goto END;} Else{strbuffer = Strbuffer.substr (Ipos+strensearch.length ());}    memset (Szbuffer, 0x00, sizeof (szbuffer)); strcpy_s (Szbuffer, Strbuffer.c_str ());    Remove the middle space \ 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://Close all handles CloseHandle (hwritepipe); CloseHandle (Hreadpipe); CloseHandle (pi.hprocess); CloseHandle (Pi.hthread); return (Bret);}


C + + hardware information get motherboard serial number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.