Skip to content

Instantly share code, notes, and snippets.

@Milly
Created November 11, 2019 06:25
Show Gist options
  • Save Milly/639852c44564b0150b7895a4b06a1611 to your computer and use it in GitHub Desktop.
Save Milly/639852c44564b0150b7895a4b06a1611 to your computer and use it in GitHub Desktop.
Inject clink to cmd.exe, if it is interactive running.
@setlocal enableextensions disabledelayedexpansion
@echo off
if not x%CMDNOINIT% == x goto :done
call :check_interactive "%CMDCMDLINE:"=""%"
if ERRORLEVEL 2 goto :interactive_silent
if ERRORLEVEL 1 goto :interactive
goto :done
:check_interactive
set test="%~1"
set test=%test:|=#%
set test=%test:&=#%
set test=%test:>=#%
set test=%test:<=#%
for /F "tokens=*" %%i in (%test%) do set test=%%i
set test=%test:""="%
call :check_interactive_rel %test%
goto :eof
:check_interactive_rel
shift
if /i x%1 == x/c goto :eof
if /i x%1 == x/k exit /b 2
if x%1 == x exit /b 1
goto :check_interactive_rel
:interactive_silent
set clink_opt=--quiet --profile ~\clink
goto :interactive_core
:interactive
echo %~f0: is interactive
set clink_opt=--profile ~\clink
goto :interactive_core
:interactive_core
:: Inject clink
set clink_path="%clink_dir%\clink.bat"
if exist %clink_path% call %clink_path% inject %clink_opt%
:done
@endlocal
@Milly
Copy link
Author

Milly commented Nov 11, 2019

Usage

reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "C:\path\to\init.cmd" /f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment