@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\ ?
A huge thank you as always
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