Re enable Import Module Psreadline warning
Asked Answered
T

3

20

This warning keeps popping in the terminal of Visual Code app

Warning: PowerShell detected that you might be using a screen reader and has
         disabled PSReadLine for compatibility purposes.
         If you want to re-enable it, run 'Import-Module PSReadLine'.

Even if I change the value to 0 via regedit, the warning still shows.

Tautomer answered 22/3, 2021 at 14:53 Comment(1)
Did you reboot having set the registry value to 0?Zoltai
E
33

The implications of your symptom are:

  • Windows is in screen-reader mode (a Windows accessibility feature for the visually impaired) at the time your PowerShell session starts.

  • You're using a regular PowerShell session, either in a console window / in Windows Terminal or in Visual Studio Code's integrated terminal.

    • By contrast, if you use Visual Studio Code with the PowerShell extension, which enables a much richer PowerShell code-authoring experience, the problem doesn't occur, because the sessions provided by the extension in the so-called PowerShell Integrated Console do not perform this check (as of version 2021.2.2), and therefore do load PSReadLine (the module providing a rich command-line editing experience) and do not emit a warning. It is unclear if this unconditional override is by design or an oversight.

    • While you could follow the advice in the error message and add
      Import-Module PSReadLine to your $PROFILE file and doing so will re-enable PSReadLine for a rich command-line editing experience, but you'll still see the warning on startup, because it is emitted by PowerShell before the $PROFILE file is loaded. That said, if screen-reader mode is enabled by design on your system, this is the right solution.


If this mode is (accidentally) turned on persistently, via the registry, you can turn it off as follows:

Set-ItemProperty 'registry::HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access' On 0

Note:

  • This change requires a logoff or reboot to take effect.
  • To query the persistent mode, use:
Get-ItemPropertyValue 'registry::HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access' On

If this mode has accidentally been turned on in-OS-session, by an application that is either ill-behaved in that it doesn't turn the mode back off again or has crashed before being able to do so, you can turn the mode off ad hoc so that future PowerShell sessions in the same OS user session no longer see the warning:

The following, gratefully adapted from this GitHub comment, is a PowerShell command that does this via Add-Type and ad hoc-compiled C# code (which is necessary to perform P/Invoke calls):

# Run in PowerShell
(Add-Type -PassThru -Name ScreenReaderUtil -Namespace WinApiHelper -MemberDefinition @'
  const int SPIF_SENDCHANGE = 0x0002;
  const int SPI_SETSCREENREADER = 0x0047;

  [DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
  private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);

  public static void EnableScreenReader(bool enable)
  {
    var ok = SystemParametersInfo(SPI_SETSCREENREADER, enable ? 1u : 0u, IntPtr.Zero, SPIF_SENDCHANGE);
    if (!ok)
    {
      throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
    }
  }
'@)::EnableScreenReader($false)
Estival answered 22/3, 2021 at 16:12 Comment(5)
The registry trick worked for me.Mcgrath
if its answered very well/and its about powershell/thats mklement0 (sung to the tune of 'Thats Amore')Gentlefolk
I just installed the extention, but i dont see any effect, still getting this message. Also Im wondering this message started to occure when I started to use screen reader, but I didnt change anything in the settings of windows, was it changed by sr?Isaacisaacs
@daza, I have no explanation for your symptom, and on my Windows 11 machine the registry setting doesn't seem to change anymore when you turn on screen reader, and I don't even get the warning anymore.Estival
@daza, when I manually set the registry setting to 1 in Windows 11 - which does not correspond to turning on the screen reader - I still see the behavior described in this answer.Estival
B
4

You can also try this(just woked for me)

Step 1: Open "RUN" (WIN + R)

Step 2: Type "regedit"

Step 3: On the left side, there is a folder named "HKEY_CURRENT_USER"; click on it.

Step 4: Click the sub-folder named "Control Panel" and then click the sub-folder named "Blind access" or follow this path Computer\HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access

Step 5: Right Click on the option "On", chose the option "Modify" and then set the value 0.

Now Restart your computer, and PROBLEM SOLVED!

Bradfield answered 31/10, 2022 at 14:23 Comment(0)
M
0

If NVDA is installed, open the NVDA first. Then right click on NVDA icon on the Windows taskbar "Notification Area" and reset configuration to factory defaults. Then restart your VSCode.

enter image description here

Marmot answered 8/2 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.