Internal command line not launching the expected binary

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

User avatar
szlori
Senior Member
Senior Member
Posts: 263
Joined: 2005-01-17, 07:12 UTC
Location: Sydney

Internal command line not launching the expected binary

Post by *szlori »

My TC is 9.10, but I haven't seen any such fix in 9.12 and also couldn't find this same issue by search. Please let me know if this is by design.

I have the same (same name, but different version) application binary in different folders, let's say in folder A and B.
The one in folder A was installed by script and has entry in Windows start menu, the one in B is just installed by copying binaries.

In TC, whatever folder I select and type the name of the executable in the TC command line, it will execute the binary from folder A.
Even if my current folder is B, still the binary from folder A will be executed.
To execute the binary in folder B, I have to double-click it in the list or specify the full path in the TC command line.

Not sure why this is happening. Folder A is not even in the path and I can't for instance start the binary from any folder from inside Windows command prompt...
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Internal command line not launching the expected binary

Post by *Stefan2 »

szlori wrote: whatever folder I select and type the name of the executable in the TC command line, it will execute the binary from folder A.

Open a command prompt in WindowsTM itself and try there, what happens?




 
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

 
If you launch a app without full path, nothing will happen,
only if your current working dir is the folder with that app,
unless that app is registered by WindowsTM, then it works from everywhere.

Like "notepad", "mspaint", "Adobe Reader" ...


This info is stored in this registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

You can search your app there and change the path to a wanted one yourself.




 
User avatar
szlori
Senior Member
Senior Member
Posts: 263
Joined: 2005-01-17, 07:12 UTC
Location: Sydney

Post by *szlori »

As I wrote in the first post I can't launch the app from Windows command prompt if I'm in a different folder.

In TC my current panel contains folder B (so I assumed that is the current working folder), but still if I enter the binary name in TC command prompt, it will launch the app from folder A.

Is there something strange with my setup or somebody else can reproduce this?
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2szlori
Just to rule out any TC-setting - try and start your TC with a clean ini file (pathToTC\totalcmd64.exe /i=pathToTC\test.ini) and see if you still have the problem.

It could be that you have made a TC Alias to the program in folder A and forgot about it. An Alias name takes precedence over the same program name in a folder.

When you say:
whatever folder I select and type the name of the executable in the TC command line
does that mean that you type the name including the extension (yourprogram.exe) or just the name part (yourprogram)?
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

2szlori
I'm quite sure that Stefan2 already posted the relevant information in the second half of his second post: the executable and its path is most likely mentioned in the registry key, hence Windows always executes that particular executable instead of the one in the current working dir (in TC). CMD works in a different way, as it only executes programs in the current working dir or somewhere in the %PATH% - in other words, the registry key is not taken into account.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
siealex
Senior Member
Senior Member
Posts: 278
Joined: 2009-03-22, 16:36 UTC

Post by *siealex »

Not confirmed on TC 9.12 x32, Win10 x64. Typing "mspaint" in any folder starts Microsoft Paint. But typing "mspaint" in a folder with "mspaint.exe" (here it's a copied Victoria executable) in it starts that file.
"MSPAINT" in any folder (left panel)
[img]https://s18.postimg.cc/q4sh6fgzd/852.jpg[/img]
starts MSPAINT
[img]https://s18.postimg.cc/xxj4ydzt5/853.jpg[/img]
but the same command in this folder (right panel)
[img]https://s18.postimg.cc/s9cu7i36h/855.jpg[/img]
starts this!
[img]https://s18.postimg.cc/fuq276je1/856.jpg[/img]
We are not so S.M.A.R.T. as we imagine...
umbra
Power Member
Power Member
Posts: 871
Joined: 2012-01-14, 20:41 UTC

Post by *umbra »

I can confirm the behavior reported by szlori. And I can confirm Stefan2's note that it is related to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths.

When you type an executable's name in TC's command line and TC can choose between an executable in the current directory and a one defined in the mentioned registry key, TC will execute the one from registry and set its current directory.

I have never noticed this and it seems very unexpected to me.

TC 9.12 x86, Win 10 RS3 x64

umbra
Windows 7 Pro x64, Windows 10 Pro x64
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2siealex
mspaint.exe is not a key in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths - it is in the path variable for the pbrush.exe key though

mspaint.exe is placed in %SystemRoot%\System32\ an that is in the %PATH% environment, which is why TC executes it from any folder, where there is not another mspaint.exe file

Try your test with wordpad.exe in stead - then you will se that 2Stefan2 is right.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
szlori
Senior Member
Senior Member
Posts: 263
Joined: 2005-01-17, 07:12 UTC
Location: Sydney

Post by *szlori »

Thank you guys, firstly Stefan2 then umbra for confirming it.
It is indeed linked to the path set in "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", which is set by the installer.

Now, I understand the reason, that's fine, BUT I second umbra - for me this behavior is unexpected and I actually had a hiccup during a presentation (at work) because of this...

I would expect the TC command line to be sensitive to the current folder set in the current pane - treat that as the current working folder, so typing in the command line would execute the binary from that folder.

Imagine this:
  • you double-click the binary in the TC pane and one program is executed
  • now "Ctrl+Enter" on the binary to copy in TC command line, add some command line parameter then hit Enter to launch it - but surprise surprise - it's a different version (from a different folder) of the binary launched
Anybody here thinks that TC should take the working folder from the current pane?
I won't argue that this is a bug, it is perhaps a feature request, but I think it is a reasonable one, unless there is a very good reason behind the current behavior.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

2szlori
I agree that it would be more intuitive if TC prioritized local executable over Registry setting - that would correspond to the behaviour to the %PATH% environment variable.
now "Ctrl+Enter" on the binary to copy in TC command line, add some command line parameter then hit Enter to launch it - but surprise surprise - it's a different version (from a different folder) of the binary launched
For now I recommend that you press Shift+Ctrl+Enter in stead, then you get the executable with full path which TC respects.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I don't think that I can change that - TC just calls ShellExecuteEx, and it seems to prioritize the names from App Paths when you don't enter a path name.
Author of Total Commander
https://www.ghisler.com
User avatar
Dalai
Power Member
Power Member
Posts: 9364
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

You can even type any of the executables mentioned in that Registry key in Windows's Start > Run to execute them, even ones that are not in a directory somewhere in the %PATH%. And it's indeed caused by ShellExecute(Ex). However, I'm wondering whether or not TC correctly fills the data structure passed to that function, in particular the (current) directory.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Yes, TC does fill the current directory.
Author of Total Commander
https://www.ghisler.com
User avatar
szlori
Senior Member
Senior Member
Posts: 263
Joined: 2005-01-17, 07:12 UTC
Location: Sydney

Post by *szlori »

2petermad
For now I recommend that you press Shift+Ctrl+Enter in stead, then you get the executable with full path which TC respects.
Thanks, I knew that of course. ;)

2Christian
I don't think that I can change that
There's nothing that cannot be changed (especially by you), but I realize the workaround (see below) might be too complex compared to such specific case.
Workaround in code: check that executable is available in current working folder and, if so, automatically add the path to the file name (so what is executed is equivalent to when we pasted the full path in cmd line with Shift+Ctrl+Enter)

But I would still vote to implement this "workaround"... would you consider?
(paste here image with begging puss in boots with huge eyes)
Post Reply