【问题标题】:Re enable Import Module Psreadline warning重新启用导入模块 Psreadline 警告
【发布时间】:2021-03-22 14:53:40
【问题描述】:
此警告在 Visual Code 应用程序的终端中不断弹出
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'.
即使我通过 regedit 将值更改为 0,警告仍然显示。
【问题讨论】:
标签:
powershell
visual-studio-code
warnings
screen-readers
【解决方案1】:
您的症状的含义是:
如果此模式(不小心)持续打开,您可以通过注册表将其关闭,如下所示:
Set-ItemProperty 'registry::HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access' On 0
注意:
- 此更改需要注销或重新启动才能生效。
- 要查询持久模式,请使用:
Get-ItemPropertyValue 'registry::HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access' On
如果此模式被意外打开in-OS-session,则应用程序要么行为不端,要么不返回该模式再次关闭或在能够这样做之前崩溃,您可以临时编译 C# 代码以关闭该模式(感谢改编自 this GitHub comment),以便 未来 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)