后台创建进程和杀掉进程
后台创建进程:下面这段代码可以后台创建进程,不需要再用dos命令在cmd.exe界面操作了。
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof STARTUPINFO;
PROCESS_INFORMATION pi;
//LPTSTR szCmdline = _tcsdup(TEXT("C:\\notepad.exe D:\\file.txt"));
LPTSTR szCmdline = _tcsdup(str);
BOOL res = CreateProcess(NULL, szCmdline, NULL, NULL, NULL, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, NULL, NULL, &si, &pi); //you code ........ if (TRUE == res) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); killNodeProcess(); }
后台杀掉程序:
void killNodeProcess() { STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof STARTUPINFO; LPTSTR szCmdline = _tcsdup(TEXT("taskkill /f /im node.exe")); PROCESS_INFORMATION pi; BOOL res = CreateProcess(NULL, szCmdline, NULL, NULL, NULL, ABOVE_NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, NULL, NULL, &si, &pi); if (TRUE == res) { if (!WaitForSingleObject(pi.hProcess,INFINITE)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } }