I have a question regarding a symptom of my misuse of CreateProcess. I'm using the lpcommandline parameter to feed the path to my executable and parameters. My misuse is that I have not surrounded the path to the exe with quotes.
My question is, why does the CreateProcess work just fine on most computers and not others? I know that the path will have a space in most of the time, yet on 90% of XP machines it works. I of course found out my issue on those 10% where it did not. But I'm wondering what is different on the machines where it does not work? Is there a setting or a policy that any of you folks know about. And yes, I am going to fix the quote issue. Just curious about why something like this would not have just failed off the bat.
So the code would look something like below and the szCommandLine Parameter would be something like below. Notice no quotes around the path to the exe.
"C:\Program Files\My Company\doit.exe parameter1 parameter2"
CreateProcess(
NULL,
szCommandLine,
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si,
&pi )
As the document Martin York linked to hinted, CreateProcess() has some behaviour for back-compat with pre-long-name programs.
"c:\program files\sub dir\program name arg1 arg2" will look for:
"c:\program.exe" files\sub dir\program name arg1 arg2 "c:\program files\sub.exe" dir\program name arg1 arg2 "c:\program files\sub dir\program.exe" name arg1 arg2 "c:\program files\sub dir\program name.exe" arg1 arg2
So if any of these files exist, Windows will to call them, not your program. Also, I would assume if you did not have read access to any of the folders these possible matches are in, CreateProcess() may fail out immediatly, instead of checking if you have read to the later possible matches. (Windows by default checks read access only the final folder.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With