CreateProcess with space in file name

This doesn't work... because there is a space in the name of the .exe ;/

CreateProcessW(L"test lol.exe", NULL , NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);

This works however...

CreateProcessW(L"testlol.exe", NULL , NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);

But how can I get it working when there is a space in the file name?:O
Last edited on
Use double quotes in file name, see PathQuoteSpaces() API or write your own routine.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773739(v=vs.85).aspx

If you insist on using a literal string, then escape it like this:
CreateProcessW(L"\"test lol.exe\"", NULL , NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);
Last edited on
CreateProcessW(L"\"test lol.exe\"", NULL , NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);

Doesn't seem to be working. :(

I have no clue why but I probably screwed up pretty bad somewhere..
Passing like this should just work:
CreateProcessW(L"test lol.exe", NULL , NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);
What error are you getting? (call GetLastError() to get it)

Andy

PS The NULL after FALSE should really be 0 (it's a DWORD param, not a pointer). It works as NULL is just a #define of 0 in C++.

1
2
3
4
5
6
7
8
9
STARTUPINFO si = {0};
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi = {0};

DWORD retCode = NOERROR;
if(!CreateProcessW(L"test lol.exe", NULL , NULL, NULL,
    FALSE, 0, NULL, NULL, &si, &pi)) {
    retCode = GetLastError();
}

Topic archived. No new replies allowed.