AveYo / LeanAndMean

snippets for power users
MIT License
239 stars 37 forks source link

[RunAsTI] Please add "Open command prompt here as TI" #9

Open ggbbrr opened 11 months ago

ggbbrr commented 11 months ago

Similar to the more common "open command prompt here" or "open command prompt here as admin".

(for directories & directory background)

Thanks.

AveYo commented 10 months ago

It's doable but then how many different prompts will you end up with? It's trivial to start cmd in powershell as TI

ggbbrr commented 10 months ago

Here's how I currently do it with NSudo. And I find it very useful to just right click a folder and choose this option :

`@ECHO off SETLOCAL EnableDelayedExpansion CD /d "%~dp0"

NET SESSION >NUL 2>&1 IF NOT %ERRORLEVEL% == 0 ( ECHO Please run this batch file as ADMIN. Aborting PAUSE EXIT )

SET "_file_name=NSudoLC.exe"

) SET "_file_path=%~dp0%_file_name%" SET "_menu_text=Open command prompt here as TI (NSudo)" SET "_keycommand=Command" SET "_keyicon=Icon" SET "_regkey1=HKCU\Software\Classes\Drive\shell\%_menu_text%" SET "_regkey2=%_regkey1%\%_keycommand%" SET "_regkey3=HKCU\Software\Classes\Directory\shell\%_menu_text%" SET "_regkey4=%_regkey3%\%_keycommand%" SET "_regkey5=HKCU\Software\Classes\Directory\Background\shell\%_menu_text%" SET "_regkey6=%_regkey5%\%_keycommand%"

IF NOT EXIST "%_file_path%" ( ECHO error : Cannot find "%_file_name%" in current directory. Exiting. PAUSE EXIT )

REG.EXE QUERY "%_regkey1%" /ve >NUL 2>NUL IF ERRORLEVEL 1 ( CHOICE /c ix /n /m "Type i to install '%_menu_text%'. Or type x to exit:" IF errorlevel 2 EXIT

REG.EXE add "%_regkey2%" /v "" /t REG_SZ /d "\"%~dp0%_file_name%\" -U:T cmd.exe /s /k pushd \"%%V\"" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey2%". & PAUSE

REG.EXE add "%_regkey1%" /v "%_keyicon%"        /t REG_SZ /d "\"%~dp0%_file_name%\",0"  /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey1%". & PAUSE

REG.EXE add "%_regkey4%" /v "" /t REG_SZ /d "\"%~dp0%_file_name%\" -U:T cmd.exe /s /k pushd \"%%V\"" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey4%". & PAUSE

REG.EXE add "%_regkey3%" /v "%_keyicon%"        /t REG_SZ /d "\"%~dp0%_file_name%\",0"  /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey3%". & PAUSE

REG.EXE add "%_regkey6%" /v "" /t REG_SZ /d "\"%~dp0%_file_name%\" -U:T cmd.exe /s /k pushd \"%%V\"" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey6%". & PAUSE

REG.EXE add "%_regkey5%" /v "%_keyicon%"        /t REG_SZ /d "\"%~dp0%_file_name%\",0"  /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : creating reg key "%_regkey5%". & PAUSE

) ELSE ( CHOICE /c ux /n /m "Type u to UNinstall '%_menu_text%'. Or type x to exit:" IF errorlevel 2 EXIT

reg.exe delete "%_regkey1%" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : deleting reg key "%_regkey1%". & PAUSE

reg.exe delete "%_regkey3%" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : deleting reg key "%_regkey3%". & PAUSE

reg.exe delete "%_regkey5%" /f >NUL 2>NUL
if ERRORLEVEL 1 ECHO  ERROR : deleting reg key "%_regkey5%". & PAUSE

)

EXIT

` If you think it's worth doing ... Or even correcting the code above ... :-)

Thanks, anyway.