创建进程API CreateProcess Demo

#include <windows.h> #include "console.h" int main() { PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); CHAR szSysPath[MAX_PATH]; if (GetSystemDirectory(szSysPath,MAX_PATH)>0)//get windows system dir { strcat_s(szSysPath,MAX_PATH,"//notepad.exe"); if(CreateProcess(szSysPath,"",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) { WaitForSingleObject(pi.hThread,INFINITE);//wait until quit notepad.exe } } return 0; } 

如果指定CREATE_SUSPENDED:

 

#include <windows.h> #include "console.h" int main() { PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); CHAR szSysPath[MAX_PATH]; if (GetSystemDirectory(szSysPath,MAX_PATH)>0)//get windows system dir { strcat_s(szSysPath,MAX_PATH,"//notepad.exe"); if(CreateProcess(szSysPath,"",NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi)) { ResumeThread(pi.hThread);//if CREATE_SUSPENDED si specified call ResumeThread to start notepad.exe WaitForSingleObject(pi.hThread,INFINITE);//wait until quit notepad.exe } } return 0; } 

你可能感兴趣的:(windows,api,null,System,Path,include)