Windows programming uses DxDiag to get user's machine hardware and OS information

Source: Internet
Author: User

The hardware and OS information of the machine is very helpful when diagnosing problems on the user's machine. The code to check the hardware information on the machine is very heavy, and here's a quick and easy way to use Windows's own tool Dxdiag.exe to generate reports of hardware detections, and then read the report files.

The sample code is as follows:

Startupinfo si = {sizeof (SI), 0};
process_information pi = {0};
TCHAR Szcmdline[max_path] = _t ("dxdiag.exe/whql:off/t dxdiag_output.txt");
if (CreateProcess (
null,
szCmdLine,
null,
null,<             br> TRUE,
null,
NULL,
NULL,
&si,
&PI))
{

WaitForSingleObject (pi.hprocess, INFINITE);/wait for dxdiag.exe execution to end
C Losehandle (pi.hprocess);
CloseHandle (Pi.hthread);

//Read the Dxdiag_output.txt file to obtain the hardware/os information for the user's machine
HANDLE hfile = CreateFile (_t ("Dxdiag_output.txt"), Generic_read, File_share_read, NULL, open_existing, file_attribute_normal, NULL);          
if (hfile!= invalid_handle_value)
{
DWORD dwbytesread = 0;
Char Szbuffer[buffer_size];
ReadFile (hfile, Szbuffer, Buffer_size-1, &dwbyTesread, NULL);

...     

}
CloseHandle (hfile);
}
}

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.