1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include <errhandlingapi.h> #include <handleapi.h> #include <minwindef.h> #include <processthreadsapi.h> #include <stdio.h> #include <winnt.h>
BOOL CreateChildProcess(PTCHAR szChildProcessName,PTCHAR szCommandLine){ STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&pi,sizeof(pi)); ZeroMemory(&si,sizeof(si)); si.cb = sizeof(si); if(!CreateProcess( szChildProcessName, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi )){
printf(TEXT("CreateProcess 失败,错误码: %lu\n"), GetLastError()); return FALSE; } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return TRUE; }
int main(int argc, char *argv[]) { TCHAR szApplicationName[] = TEXT("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"); TCHAR szCmdline[] = TEXT(""); CreateChildProcess(szApplicationName,szCmdline); getchar(); return 0; }
|