Windows BATCH:如何禁用单个脚本的快速编辑模式? [英] Windows BATCH: How to disable QuickEdit Mode for individual scripts?

查看:24
本文介绍了Windows BATCH:如何禁用单个脚本的快速编辑模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您希望直接从命令提示符快速突出显示和复制文本,而不是将输出重定向到文件,则快速编辑模式会很有用.但是,它也有其缺点.如果您正在运行批处理脚本,则在控制台中选择文本将暂停脚本执行,直到取消选择文本.如果脚本预计会不间断地继续,这可能是个问题.

QuickEdit mode can be useful if you wish to quickly highlight and copy text directly from the command prompt instead of redirecting output to a file. However, it has its drawbacks. If you have a batch script running, selecting text in the console will pause the script execution until the text is deselected. This can be a problem if the script is expected to continue without pause.

如何禁用某些 BATCH 脚本的快速编辑模式?

How can one disable QuickEdit mode for certain BATCH scripts?

推荐答案

很遗憾,无法从命令行编辑当前 CMD 控制台实例的 QuickEdit 设置.但是,我们可以暂时禁用全局 QuickEdit 设置并启动一个新的控制台实例.有几种方法可以做到这一点,每种方法都有自己的优点(优点)和缺点(缺点).以下两种解决方案都需要能够修改注册表.

Unfortunately, there is no way to edit the QuickEdit setting of the current CMD Console instance from command line. We can, however, temporarily disable the global QuickEdit setting and start a new console instance. There are a couple ways to do this, each with its own perks (pros) and drawbacks (cons). Both of the following solutions require the ability to modify the registry.

  1. REGEDIT

  • 专业版:兼容任何常见的 Windows 系统
  • CON:需要创建临时 REG 文件

  • PRO: Compatible with any common Windows system
  • CON: Requires the creation of temporary REG files

代码(位于脚本的开头):

Code (goes at the beginning of your script):

if exist "%TEMP%consoleSettingsBackup.reg" regedit /S "%TEMP%consoleSettingsBackup.reg"&DEL /F /Q "%TEMP%consoleSettingsBackup.reg"&goto :mainstart
regedit /S /e "%TEMP%consoleSettingsBackup.reg" "HKEY_CURRENT_USERConsole"
echo REGEDIT4>"%TEMP%disablequickedit.reg"
echo [HKEY_CURRENT_USERConsole]>>"%TEMP%disablequickedit.reg"
(echo "QuickEdit"=dword:00000000)>>"%TEMP%disablequickedit.reg"
regedit /S "%TEMP%disablequickedit.reg"
DEL /F /Q "%TEMP%disablequickedit.reg"
start "" "cmd" /c "%~dpnx0"&exit

:mainstart

REG

  • 专业版:不需要创建临时文件
  • CON:在没有 Resource Kit 的 Windows 2000 和更早版本上不可用
  • CON:不同的版本有不同的语法(在下面的代码中说明)

  • PRO: Does not require creation of temp files
  • CON: Not available on Windows 2000 and earlier without Resource Kit
  • CON: Different versions have different syntax (accounted for in code below)

代码(位于脚本的开头):

Code (goes at the beginning of your script):

set reg50=::&set reg51=::&(reg /?>nul 2>&1 && set reg51=)
if %errorlevel%==5005 set reg50=
set qkey=HKEY_CURRENT_USERConsole&set qprop=QuickEdit
%reg51%if defined qedit_val (echo y|reg add "%qkey%" /v "%qprop%" /t REG_DWORD /d %qedit_val%&goto :mainstart)
%reg50%if defined qedit_val (reg update "%qkey%\%qprop%"=%qedit_val%&goto :mainstart)
%reg51%for /f "tokens=3*" %%i in ('reg query "%qkey%" /v "%qprop%" ^| FINDSTR /I "%qprop%"') DO set qedit_val=%%i
%reg50%for /f "tokens=3*" %%i in ('reg query "%qkey%\%qprop%"') DO set qedit_val=%%i
if "%qedit_val%"=="0" goto :mainstart
if "%qedit_val%"=="0x0" goto :mainstart
%reg51%echo y|reg add "%qkey%" /v "%qprop%" /t REG_DWORD /d 0
%reg50%if "%qedit_val%"=="" reg add "%qkey%\%qprop%"=0 REG_DWORD
%reg50%if "%qedit_val%"=="1" reg update "%qkey%\%qprop%"=0
start "" "cmd" /c set qedit_val=%qedit_val% ^& call "%~dpnx0"&exit

:mainstart

如果您有其他解决方案,请随时发布.

If you have another solution, feel free to post.

这篇关于Windows BATCH:如何禁用单个脚本的快速编辑模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆