I am trying to execute a dos command using CreateProcess function :
LPWSTR cmd=(LPWSTR)QString("C:\\windows\\system32\\cmd.exe subst " + DLetter+" \""+mountPath+"\"").utf16();
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if ( CreateProcessW(0, // Application name
cmd, // Application arguments
NULL,
NULL,
TRUE,
0,
NULL,
L"C:\\windows\\system32", // Working directory
&si,
&pi) == TRUE)
{ ...
it give as last error 3 = ERROR_PATH_NOT_FOUND, when I separate the application path "C:\\windows\\system32\\cmd.exe" from the command it shows the console without executing my subst command.
Any help will be appreciated.
You need to include either /C or /K in the options to
cmd.exe.Without one these options, the
substcommand that you pass is simply ignored.Having said that,
subst, at least on my Windows 7 box, is not implemented insidecmd.exe. It is a separate executable. So you can invoke it directly and bypasscmd.execompletely.Regarding your call to
CreateProcessI have the following comments:C:\\windows\\system32. Just invokesubst.exeand let the system locate the executable using the standard search path.FALSEforbInheritHandles. You aren’t passing any handles to the new process and so you don’t need the new process to inherit your handles.NULLas the working directory. There’s just no need to specify it here.