首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >警告原因: PowerShell检测到您可能正在使用屏幕读取器,并且出于兼容性目的禁用了PSReadLine。

警告原因: PowerShell检测到您可能正在使用屏幕读取器,并且出于兼容性目的禁用了PSReadLine。
EN

Server Fault用户
提问于 2020-04-29 09:03:42
回答 2查看 31.8K关注 0票数 16

步骤

在Windows 10上启动PowerShell 7。

实际结果

代码语言:javascript
复制
PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

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'.

预期结果

PowerShell启动时不显示警告,因为我没有使用屏幕阅读器。

解决方案

运行指定的命令Import-Module PSReadLine。自从我第一次想要理解为什么这里有警告以来,我就没有运行过它。

$PSVersionTable输出:

代码语言:javascript
复制
Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

附加信息

我安装了Visual 2017,2019

EN

回答 2

Server Fault用户

回答已采纳

发布于 2020-05-05 06:35:18

设置以下注册表项:

代码语言:javascript
复制
Windows Registry 
Computer\HKEY_CURRENT_USER\Control Panel\Accessibility\Blind Access\On

若要评估0和重新启动,请执行以下操作。

我通过@Znatz提到的问题找到了这个替代解决方案。

来源

票数 25
EN

Server Fault用户

发布于 2020-05-05 02:40:22

对此错误有一个修正。

Powershell问题#11751

创建一个.ps1文件,粘贴以下代码并使用powershell运行它。

代码语言:javascript
复制
Add-Type -TypeDefinition '
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

public static class ScreenReaderFixUtil
{
    public static bool IsScreenReaderActive()
    {
        var ptr = IntPtr.Zero;
        try
        {
            ptr = Marshal.AllocHGlobal(sizeof(int));
            int hr = Interop.SystemParametersInfo(
                Interop.SPI_GETSCREENREADER,
                sizeof(int),
                ptr,
                0);

            if (hr == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return Marshal.ReadInt32(ptr) != 0;
        }
        finally
        {
            if (ptr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
    }

    public static void SetScreenReaderActiveStatus(bool isActive)
    {
        int hr = Interop.SystemParametersInfo(
            Interop.SPI_SETSCREENREADER,
            isActive ? 1u : 0u,
            IntPtr.Zero,
            Interop.SPIF_SENDCHANGE);

        if (hr == 0)
        {
            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
    }

    private static class Interop
    {
        public const int SPIF_SENDCHANGE = 0x0002;

        public const int SPI_GETSCREENREADER = 0x0046;

        public const int SPI_SETSCREENREADER = 0x0047;

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

if ([ScreenReaderFixUtil]::IsScreenReaderActive()) {
    [ScreenReaderFixUtil]::SetScreenReaderActiveStatus($false)
}
票数 15
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1014754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档