The error code 2 means "The system cannot find the file specified". Probably it cannot find "xxx.exe"
Try specifying the path: CreateProcess(L"C:\MyFiles\xxx.exe", cmd, ...).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi all, I've been struggling with the WinAPI CreateProcess for some time now.
CreateProcess failed
Error code = 2
How to fix it?
CreateProcess(L"xxx.exe",
cmd,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi)
The error code 2 means "The system cannot find the file specified". Probably it cannot find "xxx.exe"
Try specifying the path: CreateProcess(L"C:\MyFiles\xxx.exe", cmd, ...).
This is a well-known problem with CreateProcess. See Creating Processes; use NULL for the ApplicationName (first parameter) and use the executable path and filename in the second parameter.
You can use GetModuleFileName if your .exe is in the main executable directory
Like :
WCHAR wszExe[MAX_PATH] = L"xxx.exe";
WCHAR wszDrive[MAX_PATH], wszDir[MAX_PATH], wszModule[MAX_PATH], wszPath[MAX_PATH];
GetModuleFileName(NULL, wszModule, MAX_PATH);
_wsplitpath(wszModule, wszDrive, wszDir, NULL, NULL);
swprintf(wszPath, L"%s%s%s", wszDrive, wszDir, wszExe);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
CreateProcess(NULL, wszPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);