#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
if (CreateProcess(L"RUN_TEST.bat",// RUN_TEST.bat位于工程所在目录下
NULL,
NULL,
NULL,
FALSE,
CREATE_NO_WINDOW,// 这里不为该进程创建一个控制台窗口
NULL,
NULL,
&si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);// 等待bat执行结束
CloseHandle(pi.hProcess); CloseHandle(pi.hThread);
}
return 0;}
1.调用SHELL bat
::ShellExecute(NULL, "open", pszPName, "参数1 参数2
参数3", NULL, SW_SHOW);
HINSTANCE ShellExecute( HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
2.创建一个新的进程。进程传入参数说明
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,(welcomebbs)
LPPROCESS_INFORMATION lpProcessInformation
);