question

winrtcapture-7351 avatar image
0 Votes"
winrtcapture-7351 asked winrtcapture-7351 commented

CreateProcess

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)

windows-api-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
2 Votes"
Viorel-1 answered winrtcapture-7351 commented

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, ...).


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How to use relative path?

0 Votes 0 ·

How to use relative path?

Relative to what?

Give an example.

  • Wayne

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 winrtcapture-7351 ·

Take the time to read the documentation for the Windows API functions that you are trying to use. The documentation of the lpApplicationName and lpCommandLine parameters to CreateProcess discusses how the function uses paths and searches for the executable file.


0 Votes 0 ·

Thanks.

0 Votes 0 ·
SimpleSamples avatar image
1 Vote"
SimpleSamples answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered winrtcapture-7351 commented

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);



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.