WAD internal "which" should check for FILEEXIST when using AppPaths entry

#1
Hi,

it's a nice idea to check registry AppPaths as well as %PATH in "which" - in principle.
In practice, the command should check wether a file found via AppPaths really exists before returning it - otherwise you get non-existant returns erroneously left over from old uninstalls... eg if manual uninstall of a product did NOT remove the AppPaths entry.
 

rconn

Administrator
Staff member
May 14, 2008
10,506
94
#2
WAD. The AppPaths check is done in the path search, not by WHICH.

You can make a new feature request in the Suggestions Forum if you want WHICH to add a check for the file existence. (But it means that WHICH will *not* return the same result as if you tried to execute the specified command name -- in the case of a bad AppPaths entry, you'd get an error message from Windows.)
 
Nov 2, 2008
180
0
#3
If apppath is pointing to a non-existant file, you should fix apppath. Programs that use apppath would be disappointed. I use the APPPATH.CPL by Mike Linn to do this. I'm just wondering if there is a cunning trick you can do in tcmd to run an apppath proggie from its name.
 
May 29, 2008
529
3
Groton, CT
#4
If apppath is pointing to a non-existant file, you should fix apppath. Programs that use apppath would be disappointed. I use the APPPATH.CPL by Mike Linn to do this. I'm just wondering if there is a cunning trick you can do in tcmd to run an apppath proggie from its name.
Would you give us a pointer to this applet, please?
 
#6
Here's a slightly tidier version.
Code:
v:\> type apppathfix.btm
set apppath=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
do x in /p regdir /s1 %apppath
        set key=%apppath\%@ltrim[" ",%x]
        set target=%@regquery["%key\"]
        if "%target" EQ "-1" iterate
        iff not exist "%target" then
                echo Bogus: Key: %key  @: %target
        endiff
enddo
Code:
v:\> apppathfix.btm
Bogus: Key: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe  @: G:\7Zip\7zFM.exe
Bogus: Key: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\mbam.exe  @: G:\Malwarebytes\mbam.exe
 
#9
Find apppath here https://www.gregorybraun.com/ . It comes in an exe too.
Cute app. I looked at it only briefly and it didn't seem to identify bogus entries. I did finish my BTM. Here it is, followed by two examples, one not elevated and one elevated.
Code:
:: CLEANAPPPATH.BTM
set apppath=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
do x in /p regdir /s1 %apppath
        set key=%apppath\%@ltrim[" ",%x]
        set target=%@regquery["%key\"]
        if "%target" EQ "-1" iterate
        iff not exist "%target" then
                echo Bogus key: %key  @: %target^r^n
                echo Here's what's in it:^r^n
                regdir /v /d "%key"
                unset response
                inkey /c /k"yn" ^r^nWould you like to delete this key [YN]? ... ^s %%response
                iff "%response" EQ "y" then
                        if %_elevated NE 1 (echo ^r^nThe session must be elevated to delete a key. & iterate)
                        if %@regdelkey["%key"] EQ 1 (echo Key deleted) else (echo Key was not deleted)
                endiff
        endiff
enddo
upload_2017-7-31_13-4-39.png

upload_2017-7-31_13-5-35.png