查看clink.bat 文件
让我们看看clink.bat文件:
:: Copyright (c) 2012 Martin Ridgers
:: License: http://opensource.org/licenses/MIT
@echo off
:: Mimic cmd.exe's behaviour when starting from the start menu.
if /i "%1"=="startmenu" (
cd /d "%userprofile%"
shift /1
)
:: Check for the --profile option.
if /i "%1"=="--profile" (
set clink_profile_arg=--profile "%~2"
shift /1
shift /1
)
:: If the .bat is run without any arguments, then start a cmd.exe instance.
if "%1"=="" (
call :launch
goto :end
)
:: Pass through to appropriate loader.
if /i "%processor_architecture%"=="x86" (
"%~dp0\clink_x86.exe" %*
) else if /i "%processor_architecture%"=="amd64" (
if defined processor_architew6432 (
"%~dp0\clink_x86.exe" %*
) else (
"%~dp0\clink_x64.exe" %*
)
)
:end
set clink_profile_arg=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:launch
start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
exit /b 0
这是很好的注释,所以我们可以看到以下时间结构:
- 移至
%userprofile% 文件夹
- 如果调用格式为
clink.bat --profile PROFILE_DIR,则将clink_profile_arg 设置为PROFILE_DIR 的值
- 如果没有参数跳转到
launch代码然后结束(通过跳转到文件末尾)
- 根据系统架构选择合适的
.exe(技术上调用该函数的进程架构:Possible values of %PROCESSOR_ARCHITECTURE%)
-
launch“定义”(技术上是标签)
您已经正确识别出launch标记的代码是可以更改的,让我们进一步看看:
start "Clink" cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
因此,这会运行带有一些参数的start 命令,包括字符串“Clink”以及带有自己命令行参数的cmd.exe。 %~dpnx0being: drive,path,name,extension,0 第一个参数(参见syntax-args)和%clink_profile_arg% 之前定义的变量。
看着start:
启动单独的命令提示符窗口以运行指定的程序或命令。
粗体强调是我自己的,但我们现在可以立即看到您为什么会观察到您所描述的行为。
我们现在有几个选择要考虑。
选项 1 - 基于 clink.bat 的新 clink_terminal.bat
虽然我们可以编辑clink.bat,但更好的选择是制作一个单独的文件,仅用于终端。
我们可以简单地将:launch 更改为:
cmd.exe /s /k ""%~dpnx0" inject %clink_profile_arg%"
然后将commandline: 与clink_terminal.bat 一起使用。
选项 2 - 直接使用 clink 及其命令行参数
希望通过您已经看到,您可以有效地替换调用 .bat 并直接使用其参数直接调用 clink。
这里假设您使用的是 x64 机器:
commandline: "cmd.exe /s /k "PATH_TO_CLINK\\clink_x64.exe inject --profile PROFILE_DIR""
设置 GUID !!!
终端中的所有配置文件都有一个 GUID,您可以轻松地自己生成一个。
打开一个 PowerShell 窗口并运行 new-guid
PS C:\ANYWHERE> New-Guid
Guid
----
c97d08e9-03fc-491f-bbd7-9a12b9d6e191