Page 1 of 1

interesting run SC bug [NotABug]

Posted: 18 Jun 2014 11:06
by bdeshi
Try this:

Code: Select all

::writefile("echo.bat", "cmd /K echo HI!", o); run "echo.bat";
Right, that went well. Now try this:

Code: Select all

::writefile("cmd.bat", "cmd /K echo HI!", o); run "cmd.bat";
Did it go well too?
Now, try the first code again.

Re: interesting run SC bug.

Posted: 18 Jun 2014 13:22
by admin
Wow, what's that?! Same BAT behavior in Explorer. And when you move the BAT to a new location it behaves normal again. Looks like a Windows bug to me.

Re: interesting run SC bug.

Posted: 18 Jun 2014 13:31
by bdeshi
Yeah, I suspected MS might have a hand in it.
It's so... unimaginable!
I guess XY is off the hook for this one. Or did you fix it already? :wink:

Re: interesting run SC bug.

Posted: 18 Jun 2014 13:45
by TheQwerty
No bug.

Executing a program without specifying its extension causes Windows to search for the first matching executable using the extensions defined by %PATHEXT% in the working directory and if none is found there search the locations specified by %PATH%. (There is also some registry diving but I cannot recall the details at present.)

If you had used 'cmd.exe /K echo HI!' it would work as you expect.
However, '%ComSpec% /K echo HI!' is better still.


EDIT: Some further information...

From a command prompt there is no registry diving.
It checks the current directory and each location in %path% for 'cmd.*'.
If/when a match is found it then goes through the extensions in %pathext% checking for 'cmd.<ext>'.
It repeats this until a match is found or it exhausts %path%.

From the Run dialog or Start menu...
It checks 'HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\cmd.exe' and the same under 'HKLM'.
If either key is a match it will attempt to use the '(Default)' key's value as the path to the executable (and maybe some other child keys - I'm not positive).
Otherwise it does the same as above.

Granted this is Windows 7 so it may have changed since.