CreateProcessW()

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi,i want to start a batch in a unicode environment and redirect its stdout and errout streams. thats why i need to use CreateProcessW() function.

msdn lib days, u should pass the shell as lpApplicationName and /c + batchfor lpCommandLine. i tried that. it didnt work.

next step was to pass the shell + /c + batch for lpCommandLine and leave lpApplicationName NULL. it didnt work.

next step was this:

<div class=codeseg>
<div class=codecontent>
<div class=codesniptitle><span style="width:100% Code Snippet


WCHAR cmd[] = L"C:\WINNT\system32\cmd.exe /c pause";

    LPCWSTR dir = L"app";

    STARTUPINFO si;
    memset(&si, 0, sizeof(si));
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESTDHANDLES;

    PROCESS_INFORMATION pi;
    LPSTARTUPINFOW si_w = (LPSTARTUPINFOW) &si;

    bool success = CreateProcessW(NULL, cmd, 0, 0, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, NULL, dir, si_w, &pi);

to see if the shell receives the argument. no it didnt. the new console windows for the child popped up and immediatley closed. no pause command was executed.


next step was that i did write a small program to output the parameters delivered in _TCHAR* argv[]

i tried executing it by passing the exe as lpApplicationName and a few test parameters for lpCommandLine and it tried executiong it passing lpApplicationName NULL and my exe + test parameters for lpCommandLine. both didnt work. nothing happened. the parameter test program has a getchar(); as last function call, so i need to close it explicitly. anyway the created child console closed itself just like the tries before. all paths are correct and delivered absolute. it tried it by changing one letter of my parameter testing exe. the CreateProcessW() call failed and GetLastError() delivered 2 (FILE NOT FOUND)

so any ideas?


View the full article
 
Back
Top