猿问

以下例子,请问VC++如何用CreateProcess函数打开一个程序?

比如程序在D:\QQ.exe
谢谢了!!!

偶然的你
浏览 414回答 1
1回答

慕码人2483693

#include <windows.h>#include <stdio.h>#include <tchar.h>int main(){TCHAR szExe[] = _T("D:\\QQ.exe");TCHAR szCmd[16] = {0};STARTUPINFO si;PROCESS_INFORMATION pi;si.cb = sizeof(STARTUPINFO);GetStartupInfo(&si);if(!CreateProcess(szExe, szCmd,NULL, // process infoNULL, // thread infoTRUE, // inheritable0, // creation flagsNULL, // environmentNULL, // current directory&si, & pi)){printf(_T("open process: %s failed with error: %d\n"), szExe, GetLastError());}else{CloseHandle(pi.hProcess);CloseHandle(pi.hThread);}}
随时随地看视频慕课网APP
我要回答