1

Does anyone know how to enable or disable programmatically the "Quick Edit Mode" in PowerShell or CMD console ?
I would like to lauch PowerShell from a script (batch) and to give the same look and behavior as the default PowerShell console lauched from the shortcut.

Nicolas
  • 6,289
  • 4
  • 36
  • 51

3 Answers3

2

For anybody still looking for a solution, this will disable Quick Edit in the current PowerShell window (tested for windows 10):

Add-Type -MemberDefinition @"
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetStdHandle(int handle);
"@ -Namespace Win32 -Name NativeMethods
$Handle = [Win32.NativeMethods]::GetStdHandle(-10)
return [Win32.NativeMethods]::SetConsoleMode($Handle, 0x0080)

Per this script the first call gets the current STDIN, and per this script the second call invokes the SetConsoleMode API with the right value.

MaartenK
  • 21
  • 3
1

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

reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /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% == 0x0 (
  :: Disable QuickEdit Mode
  reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /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

viachm
  • 41
  • 4
0

Try to set/create a QuickEdit DWord value with value of 1 under the following regkey:

HKEY_CURRENT_USER\Console\<look for powershell related key>
Shay Levy
  • 121,444
  • 32
  • 184
  • 206