You need to include either /C or /K in the options to cmd.exe
.
/C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains
Without one these options, the subst
command that you pass is simply ignored.
Having said that, subst
, at least on my Windows 7 box, is not implemented inside cmd.exe
. It is a separate executable. So you can invoke it directly and bypass cmd.exe
completely.
Regarding your call to CreateProcess
I have the following comments:
- Don't include the path
C:\\windows\\system32
. Just invokesubst.exe
and let the system locate the executable using the standard search path. - Pass
FALSE
forbInheritHandles
. You aren't passing any handles to the new process and so you don't need the new process to inherit your handles. - Pass
NULL
as the working directory. There's just no need to specify it here.