diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
index 8a38b1904c..b866815a25 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
@@ -54,16 +54,11 @@ namespace Microsoft.PowerShell
internal const int ExitCodeCtrlBreak = 128 + 21; // SIGBREAK
internal const int ExitCodeInitFailure = 70; // Internal Software Error
internal const int ExitCodeBadCommandLineParameter = 64; // Command Line Usage Error
- private const uint SPI_GETSCREENREADER = 0x0046;
#if UNIX
internal const string DECCKM_ON = "\x1b[?1h";
internal const string DECCKM_OFF = "\x1b[?1l";
#endif
- [DllImport("user32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
-
///
/// Internal Entry point in msh console host implementation.
///
@@ -1680,35 +1675,6 @@ namespace Microsoft.PowerShell
}
}
- ///
- /// Check if a screen reviewer utility is running.
- /// When a screen reader is running, we don't auto-load the PSReadLine module at startup,
- /// since PSReadLine is not accessibility-friendly enough as of today.
- ///
- private bool IsScreenReaderActive()
- {
- if (_screenReaderActive.HasValue)
- {
- return _screenReaderActive.Value;
- }
-
- _screenReaderActive = false;
- if (Platform.IsWindowsDesktop)
- {
- // Note: this API can detect if a third-party screen reader is active, such as NVDA, but not the in-box Windows Narrator.
- // Quoted from https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-systemparametersinfoa about the
- // accessibility parameter 'SPI_GETSCREENREADER':
- // "Narrator, the screen reader that is included with Windows, does not set the SPI_SETSCREENREADER or SPI_GETSCREENREADER flags."
- bool enabled = false;
- if (SystemParametersInfo(SPI_GETSCREENREADER, 0, ref enabled, 0))
- {
- _screenReaderActive = enabled;
- }
- }
-
- return _screenReaderActive.Value;
- }
-
private static bool LoadPSReadline()
{
// Don't load PSReadline if:
@@ -1759,7 +1725,6 @@ namespace Microsoft.PowerShell
bool psReadlineFailed = false;
// Load PSReadline by default unless there is no use:
- // - screen reader is active, such as NVDA, indicating non-visual access
// - we're running a command/file and just exiting
// - stdin is redirected by a parent process
// - we're not interactive
@@ -1770,26 +1735,18 @@ namespace Microsoft.PowerShell
ReadOnlyCollection defaultImportModulesList = null;
if (!customConfigurationProvided && LoadPSReadline())
{
- if (IsScreenReaderActive())
+ // Create and open Runspace with PSReadline.
+ defaultImportModulesList = DefaultInitialSessionState.Modules;
+ DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" });
+ consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState);
+ try
{
- s_theConsoleHost.UI.WriteLine(ManagedEntranceStrings.PSReadLineDisabledWhenScreenReaderIsActive);
- s_theConsoleHost.UI.WriteLine();
+ OpenConsoleRunspace(consoleRunspace, args.StaMode);
}
- else
+ catch (Exception)
{
- // Create and open Runspace with PSReadline.
- defaultImportModulesList = DefaultInitialSessionState.Modules;
- DefaultInitialSessionState.ImportPSModule(new[] { "PSReadLine" });
- consoleRunspace = RunspaceFactory.CreateRunspace(this, DefaultInitialSessionState);
- try
- {
- OpenConsoleRunspace(consoleRunspace, args.StaMode);
- }
- catch (Exception)
- {
- consoleRunspace = null;
- psReadlineFailed = true;
- }
+ consoleRunspace = null;
+ psReadlineFailed = true;
}
}
@@ -3102,7 +3059,6 @@ namespace Microsoft.PowerShell
private bool _setShouldExitCalled;
private bool _isRunningPromptLoop;
private bool _wasInitialCommandEncoded;
- private bool? _screenReaderActive;
// hostGlobalLock is used to sync public method calls (in case multiple threads call into the host) and access to
// state that persists across method calls, like progress data. It's internal because the ui object also
diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx
index a57d044a8b..2c0b015475 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx
+++ b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx
@@ -132,9 +132,6 @@
[Restricted Language Mode]
-
- 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'.
-
{1} A new PowerShell preview release is available: v{0} {2}
{1} Upgrade now, or check out the release page at:{3}{2}
@@ -162,9 +159,9 @@
[-CustomPipeName <string>] [-EncodedCommand <Base64EncodedCommand>]
[-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
[-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
- [-NoProfileLoadTime] [-OutputFormat {Text | XML}]
- [-SettingsFile <filePath>] [-SSHServerMode] [-STA]
- [-Version] [-WindowStyle <style>]
+ [-NoProfileLoadTime] [-OutputFormat {Text | XML}]
+ [-SettingsFile <filePath>] [-SSHServerMode] [-STA]
+ [-Version] [-WindowStyle <style>]
[-WorkingDirectory <directoryPath>]
pwsh[.exe] -h | -Help | -? | /?
diff --git a/test/powershell/Host/ScreenReader.Tests.ps1 b/test/powershell/Host/ScreenReader.Tests.ps1
deleted file mode 100644
index 1b11a0e3ff..0000000000
--- a/test/powershell/Host/ScreenReader.Tests.ps1
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-Describe "Validate start of console host" -Tag CI {
- BeforeAll {
- if (-not $IsWindows) {
- return
- }
-
- $csharp_source = @'
- using System;
- using System.Runtime.InteropServices;
-
- public class ScreenReaderTestUtility {
- private const uint SPI_SETSCREENREADER = 0x0047;
-
- [DllImport("user32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
-
- public static bool ActivateScreenReader() {
- return SystemParametersInfo(SPI_SETSCREENREADER, 1u, IntPtr.Zero, 0);
- }
-
- public static bool DeactivateScreenReader() {
- return SystemParametersInfo(SPI_SETSCREENREADER, 0u, IntPtr.Zero, 0);
- }
- }
-'@
- $utilType = "ScreenReaderTestUtility" -as [type]
- if (-not $utilType) {
- $utilType = Add-Type -TypeDefinition $csharp_source -PassThru
- }
-
- ## Make the screen reader status active.
- $utilType::ActivateScreenReader()
- }
-
- AfterAll {
- if ($IsWindows) {
- ## Make the screen reader status in-active.
- $utilType::DeactivateScreenReader()
- }
- }
-
- It "PSReadLine should not be auto-loaded when screen reader status is active" -Skip:(-not $IsWindows) {
- if (Test-IsWindowsArm64) {
- Set-ItResult -Pending -Because "Needs investigation, PSReadline loads on ARM64"
- }
-
- $output = & "$PSHOME/pwsh" -noprofile -noexit -c "Get-Module PSReadLine; exit"
- $output.Length | Should -BeExactly 2 -Because "There should be two lines of output but we got: $output"
-
- ## The warning message about screen reader should be returned, but the PSReadLine module should not be loaded.
- $output[0] | Should -BeLike "Warning:*'Import-Module PSReadLine'."
- $output[1] | Should -BeExactly ([string]::Empty)
- }
-}