11

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.

How can one disable QuickEdit mode for certain BATCH scripts?

5 Answers 5

7

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
3
  • 1
    This is super useful and super cool! Does the compiled exe require a .net framework? Or does just the batch file need it?
    – Mark Deven
    Jan 5, 2018 at 13:20
  • @MarkDodsons - Yes - both require the .net framework (which is an issue only for a some of the XP/Win2003 machines).The .net executables are not exactly the same as win32 executables.
    – npocmaka
    Jan 5, 2018 at 16:55
  • does it actually affect the current? I try quickedit 2 but it doesn't disable it. Using quickedit 3 still show it as enabled
    – Ooker
    Dec 27, 2022 at 15:25
3

Already answered here, update "QuickMode" setting in Windows Registry:

reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 0 /f

However it will not affect currently opened window. But you can reopen a window:

:: Get QuickEdit Mode setting from Windows Registry
FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKCU\Console" /v QuickEdit`) DO (
  set quickEditSetting=%%A %%B
)

if %quickEditSetting%==0x1 (
  :: Disable QuickEdit Mode
  reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 0 /f

  :: Open script in a new Command Prompt window
  start "" "%~dpnx0" %* && exit
)

... script logic here ...
exit

Additional info about HKEY_CURRENT_USER\Console Registry configuration - https://renenyffenegger.ch/notes/Windows/registry/tree/HKEY_CURRENT_USER/console/index

3
  • can you explain what exactly start "" "%~dpnx0" %* does?
    – Ooker
    Dec 27, 2022 at 19:04
  • @Ooker: it restarts the current batch script (after changing the registry) to have it running in the new context.
    – Stephan
    Feb 18 at 13:16
  • I mean the logic behind it. What does each argument mean?
    – Ooker
    Mar 12 at 7:37
2

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.

1
  • I'll give you credit for thinking outside the box. It's really frustrating that there isn't an easier way, and a batch script distributed to an end-user could 'fail' from the get-go, unless we want to 'hack' around a little bit. Oct 21, 2016 at 19:57
1

quickedit.bat

::: TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAAClmdnY4fi3i+H4t4vh+LeL4fi2i+T4t4si9+qL4vi3i7Xbh4vg+LeLUmljaOH4t4sAAAAAAAAAAAAAAAAAAAAAUEUAAEwBAQBvnfBjAAAAAAAAAADgAA8BCwEGAAACAAAAAAAAAAAAABgQAAAAEAAAACAAAAAAQAAAEAAAAAIAAAQAAAAAAAAABAAAAAAAAAAAIAAAAAIAAAAAAAADAAAAAAAQAAAQAAAAABAAABAAAAAAAAAQAAAAAAAAAAAAAABUEQAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAudGV4dAAAAPQBAAAAEAAAAAIAAAACAAAAAAAAAAAAAAAAAAAgAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACmEQAAshEAAMQRAADWEQAAlBEAAAAAAABVi+yD7AxTVos1DBBAAGr2/9aL2IXbD4T6AAAAg/v/D4TxAAAAjUX4UFP/FQgQQACFwA+E3gAAAP8VBBBAAIXAdH+KCITJdHmA+SJ1FUCKCITJdG1AgPkidGGKCITJdfTrWYD5IHRUgPkJdE9AigiEyXXv60aA+TB0doD5T3QFgPlvdRqKUAGA+kZ0BYD6ZnUNilACgPpGdFeA+mZ0UoD5MXRWgPlPdAWA+W91DYpIAYD5TnREgPludD9AigiEyXW0i134g2X0AMHrBoPjAWoAisMEMIhF/41F9FCNRf9qAVBq9f/WUP8VABBAAIvD60iLRfgkvwyA6wWLRfgMwDlF+HQPUFP/FRAQQAD32BvAQOsmM8DrIoNl9ACNRfRqAFCNRf9qAVBq9cZF/y//1lD/FQAQQACDyP9eW8nDfBEAAAAAAAAAAAAA5hEAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKYRAACyEQAAxBEAANYRAACUEQAAAAAAAP0CU2V0Q29uc29sZU1vZGUAAKQDV3JpdGVGaWxlABABR2V0Q29tbWFuZExpbmVBADMBR2V0Q29uc29sZU1vZGUAALkBR2V0U3RkSGFuZGxlAABLRVJORUwzMi5kbGwAAAAAAAAAAAAAAAAAAA==

@setlocal disabledelayedexpansion enableextensions
@echo off

if not exist quickedit.exe (
  >quickedit.b64 (
    for /f "delims=: tokens=1" %%# in ('findstr "^:::" "%~f0"') do echo %%#
  )
  certutil -f -decode quickedit.b64 quickedit.exe >nul
  del /f /q quickedit.b64
)

quickedit.exe %*

on: quickedit 1
off: quickedit 0

5
  • My AntiVirus says quickedit.exe is malicious and quarantines it.
    – Stephan
    Feb 18 at 13:11
  • AV software have indeed been the bane of developers' existences as long as they have existed but this exercise in absolute stupidity takes the cake. As the only Windows API calls used are for setting the console mode and writing text to console, there is simply no way it could do anything malicious based on the API calls alone. Not to mention that the file is 1024 of mostly empty space, code part being only 315 bytes in size.
    – anzz1
    Feb 26 at 11:42
  • I am dumbfounded how is it even possible for an AV software to deduce that the executable could malicious, just absolutely incredible. In any case, here is the full C source in all its glory of whopping 55 lines of code: gist.github.com/anzz1/39f84c8f95168f4e3b4eae747745cde9 Finding the virus hidden in the code is left as an exercise for the reader.
    – anzz1
    Feb 26 at 11:42
  • To be clear, I'm not calling you stupid, I'm calling your AV software stupid. Users are not to blame, the companies should make passable products instead of falsely advertising them as such. I've wasted so much time sending legitimate software to various AV companies to be whitelisted that I can't even count; all the while the AV companies do nothing to stop the spread of actually malicious stuff. I cannot fully express my opinion towards AV companies within the Stack Overflow etiquette but I'm sure you can read between the lines.
    – anzz1
    Feb 26 at 11:52
  • 1
    Yeah - they call it "heuristic". Everything that looks remotely suspect (like calling an API (I doubt they even check which API, even less which function)) gets quarantined. I know the same problem with another language. Anything written in that language is "suspect" because at some time somebody used that language to write malicious code. (all fine - your comments didn't come across as "blaming ME")
    – Stephan
    Feb 26 at 12:51
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.