具体是利用systeminfo这个DOS命令的输出结果,然后保存到本地,方便我们的程序读取。
当前代码使用到了其他人的代码(隐藏执行命令行),但是找不到原来出处了,如果侵犯了大神,请艾特我,
具体代码如下
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup")
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define COMMENDLINE "systeminfo.exe"
//调用命令行命令而不显示命令行窗口
BOOL system_hide(char* CommandLine)
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead, hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead, &hWrite, &sa, 0))
return FALSE;
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (!CreateProcess(NULL, CommandLine, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &pi))
{
return FALSE;
}
CloseHandle(hWrite);
char buffer[4096] = { 0 };
DWORD bytesRead;
FILE *fp = fopen("./PCInfo.txt", "w+");
while (true)
{
memset(buffer, 0, strlen(buffer));
if (ReadFile(hRead, buffer, 4096-1, &bytesRead, NULL) == NULL)
break;
Sleep(100);
if (fp && strlen(buffer) > 100)
{fputs(buffer, fp);}
}
if (fp) fclose(fp);
return TRUE;
}
int main(int argc, char* argv[])
{
system_hide(COMMENDLINE);//不显示命令窗口
ReadInfo();
DeleteFile("./PCInfo.txt");
return 0;
}