Windows BATCH: How to disable QuickEdit Mode for individual scripts?

后端 未结 3 1568
小鲜肉
小鲜肉 2020-12-15 12:32

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 dra

相关标签:
3条回答
  • 2020-12-15 12:59

    A way that will affect the current command prompt session.

    Here's quickEdit.bat . It is a self-compiled .net script so it requires .net installed (not installed by default on Winsows XP/2003).

    Usage:

    Enable:

     quickEdit  1
    

    Disable:

     quickEdit  2
    

    Get State:

     quickEdit  3
    
    0 讨论(0)
  • 2020-12-15 13:12

    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

      • 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_USER\Console"
        echo REGEDIT4>"%TEMP%\disablequickedit.reg"
        echo [HKEY_CURRENT_USER\Console]>>"%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
        
    2. REG

      • 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_USER\Console&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.

    0 讨论(0)
  • 2020-12-15 13:26

    Slight update for option 1 that worked for me, that doesn't run it twice, on Win10, thanks.

    if exist "c:\temp\consoleSettingsBackup.reg" regedit /S "c:\temp\consoleSettingsBackup.reg" & DEL /F /Q "c:\temp\consoleSettingsBackup.reg" & goto START
    regedit /S /e "c:\temp\consoleSettingsBackup.reg" "HKEY_CURRENT_USER\Console"
    reg add "HKCU\Console" /v QuickEdit /t REG_DWORD /d 0 /f
    start "" "cmd" /c ""%~dpnx0" & exit"
    exit
    
    : START
    rem your commands\scripts here
    
    exit
    
    0 讨论(0)
提交回复
热议问题