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);
}
}