// test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include <iostream> #include <fstream> #include <string> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { TCHAR szPath[MAX_PATH]; GetSystemDirectory(szPath, sizeof(szPath)); wstring str = szPath; str.append(L"\\cmd.exe"); wstring cmdStr= L"systeminfo"; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.wShowWindow = SW_HIDE; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); TCHAR temp[2048] = L"/c systeminfo"; BOOL bRet = CreateProcess(str.c_str(), temp, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);// if (bRet) { WaitForSingleObject(pi.hProcess, 3000);// 等待程序退出 CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } system( "PAUSE "); }