Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

tcmdhere_mods.btm

Apr
1,794
15
@Charles Dye - hope you are doing well.

For the included / attached BTM - which you have modified for me in the past, I'd like to check if there is anything in "HKCR\%object\Shell\RunAs\command\" and if not then preceed as it is now. If there is something there - then tell the user what the command is and ask if they want to overwrite it and if not display a message and QUIT. this all assumes that there can only be one command under \RunAs\ ?

Code:
@echo off
rem  TCMDHere.btm
rem  This batch file adds the "TCMD prompt here" entry to Windows Explorer
rem  RunAs mods 2022-12-11 CED

setlocal
setdos /c0xff00


gosub CheckElevated

iff %_dosver ge 6.0 .and. "%_elevated" == "0" then
    echo If you are running Windows 8, 7, 2008, or Vista, you must first start a TCC
    echo session as an administrator (right click on the TCC icon and select "Run as
    echo administrator") and then run TCMDHere.btm in that session.
    quit 2
endiff


iff "%1" == "/U" then
    echo.
    echo Do you want to remove the "TCMD prompt here" entry from the Windows Explorer
    echos context (right click) menu [Y/N] ?  ``
    inkey /k"yn[enter]" %%var

    iff "%var" eq "y" then
        do object in /l Drive Directory
            echo %@regdelkey["HKCR\%object\Shell\TCMD"] > nul

            rem        Remove "RunAs" only if it points to TCmd.exe :
            
            iff %@index[%@regquery[HKCR\%object\Shell\RunAs\Command\],\tcmd.exe] != -1 then
                echo %@regdelkey[HKCR\%object\Shell\RunAs] > nul
            endiff
        enddo
    endiff
    quit
endiff


iff not exist "%@path[%_cmdspec]tcmd.exe" then
    echo "%@path[%_cmdspec]tcmd.exe" not found!  Exiting.
    quit 2
endiff


echo.
echo Do you want to add a "TCMD prompt here" entry to the Windows Explorer
echos context (right click) menus for directories and drives [Y/N] ?  ``
inkey /k"yn[enter]" %%var

if "%var" ne "y" quit 3


do object in /l Drive Directory
    echo %@regcreate["HKCR\%object\Shell\TCMD\command"] > nul

    iff %@regset["HKCR\%object\Shell\TCMD\",REG_SZ,TCMD v%_4ver &prompt here] != 0 then
        echoerr Cannot update registry key!
        quit 2    endiffe
    
    echo %@regset["HKCR\%object\Shell\TCMD\command\",REG_SZ,"%@path[%_cmdspec]tcmd.exe" /D "%%L"] > nul
    
    iff %_dosver ge 6.0 then
        echo %@regcreate["HKCR\%object\Shell\RunAs\command"] > nul

        iff %@regset["HKCR\%object\Shell\RunAs\",REG_SZ,TCMD v%_4ver prompt here (&Admin)] != 0 then
            echoerr Cannot update registry key!
            quit 2
        endiff

        echo %@regset["HKCR\%object\Shell\RunAs\command\",REG_SZ,"%@path[%_cmdspec]tcmd.exe" /D "%%L"] > nul
    endiff
enddo


echo.
echo The Windows Explorer context menus have been updated.

endlocal
quit


:CheckElevated

set _elevated=
if "%_elevated" != "" return

::  TCC/LE does not have an _ELEVATED variable.  So, try doing something
::  an unprivileged user wouldn't be allowed to do.

set _elevated=0

set r=%@random[0,9999]
set testkey=HKLM\SOFTWARE\TestElevated_%r
echo %@regcreate["%testkey"] >& nul
( echo %@regset["%testkey\",REG_SZ,%r] ) >& nul
( set t=%@regquery["%testkey\"] ) >& nul
( echo %@regdelkey["%testkey"] ) >& nul

if "%t" == "%r" set _elevated=1
return

A huge thank you as always
 
Charles (G and D), for TCCHere I do something similar, but with this.

Code:
do subkey in /L directory directory\background drive

Adding "directory\background" gives you the background of an Explorer window. That includes the desktop itself; I find that quite useful.

Mine is a little different, I use CDD (I'll try "/D") and "%V" (instead of "%L", don't know why). The '&' in the default value in the tcc key lets you select TCCHere from the context menu by pressing 't'. For example,

Code:
v:\> regdir /v /d hkcr\directory\background\shell\tcc
hkcr\directory\background\shell\tcc
   : REG_SZ : &TCCHere
  command
     : REG_SZ : "d:\tc28\tcc.exe" *cdd "%V"
 
The "/D" (instead of "*cdd") works well and seems a bit more elegant. Thanks for that.

And the '&' accelerator doesn't work for "folder"; I believe it also used by "Cut". Pressing 't' repeatedly toggles the context menu selection between "TCCHere" and "Cut".

And I also did it in HKCR\Folder (forgot about that). Apparently (just tested) that gives you things in Explorer's "Quick access" group.
 

Similar threads

Back
Top