Windows API - CreateProcess() path with space

前端 未结 5 1931
春和景丽
春和景丽 2021-01-11 13:57

How do I pass path with space to the CreateProcess() function?

The following works

STARTUPINFO si;
            PROCESS_INFORMATION pi;

            Z         


        
5条回答
  •  -上瘾入骨i
    2021-01-11 14:00

    In response to another answer, example #3 is NOT the correct one.

    The issue is that the quotes should NOT encapsulate the module pathname passed as the first parameter of CreateProcess. However, quotes SHOULD encapsulate arg0 (again module path) as passed for the command line (second parameter of CreateProcess).

    So, the correct rendition would be:

    CreateProcess(_T("c:\\master installer\\ew3d.exe"),    
                        _T("\"c:\\master installer\\ew3d.exe\" /qr"),
                        NULL,           // Process handle not inheritable
                        NULL,           // Thread handle not inheritable
                        FALSE,          // Set handle inheritance to FALSE
                        0,              // No creation flags
                        NULL,           // Use parent's environment block
                        NULL,           // Use parent's starting directory 
                        &si,            // Pointer to STARTUPINFO structure
                        &pi )           // Pointer to PROCESS_INFORMATION structure
                        ) 
    

提交回复
热议问题