You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过批处理或PowerShell获取任务栏系统图标开关状态

获取任务栏系统图标开关状态的解决方案

确认可行性

该需求完全可以实现,这些系统图标的开关状态存储在当前用户的注册表分支中,也可通过Windows Runtime API读取,以下提供两种可靠实现方式。

方法1:读取注册表(推荐)

以下PowerShell脚本直接读取对应注册表项,返回「Location」「Action Center」「Touch Keyboard」的开关状态:

# 定义要查询的图标及其对应注册表项
$iconSettings = @(
    @{Name = "Location"; RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; RegKey = "ShowLocationButton"},
    @{Name = "Action Center"; RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; RegKey = "TaskbarMn"},
    @{Name = "Touch Keyboard"; RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; RegKey = "ShowTouchButton"}
)

# 遍历查询并输出结果
foreach ($icon in $iconSettings) {
    $value = Get-ItemProperty -Path $icon.RegPath -Name $icon.RegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $icon.RegKey -ErrorAction SilentlyContinue
    $status = if ($value -eq 1) { "已开启" } else { "已关闭" }
    Write-Host "$($icon.Name): $status"
}

说明

  • 这些注册表项会随设置界面的开关操作实时更新,无需组策略配置即可生效
  • 若注册表项不存在,默认视为「已关闭」(符合Windows默认行为)

方法2:调用Windows Runtime API(适用于更复杂场景)

通过PowerShell调用Windows.UI.Shell.TaskbarManager API获取状态,这种方式直接读取系统设置,更贴近实际显示状态:

# 加载Windows Runtime API
Add-Type -AssemblyName Windows.UI
Add-Type -AssemblyName Windows.UI.Shell

$taskbarManager = [Windows.UI.Shell.TaskbarManager]::GetDefault()

# 获取各图标状态
$locationStatus = if ($taskbarManager.IsLocationButtonVisible) { "已开启" } else { "已关闭" }
$actionCenterStatus = if ($taskbarManager.IsActionCenterVisible) { "已开启" } else { "已关闭" }
# 触摸键盘需单独读取注册表,TaskbarManager暂未提供直接属性
$touchKeyboardValue = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ShowTouchButton" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ShowTouchButton -ErrorAction SilentlyContinue
$touchKeyboardStatus = if ($touchKeyboardValue -eq 1) { "已开启" } else { "已关闭" }

# 输出结果
Write-Host "Location: $locationStatus"
Write-Host "Action Center: $actionCenterStatus"
Write-Host "Touch Keyboard: $touchKeyboardStatus"

说明

  • TaskbarManager API直接对接系统任务栏服务,状态更准确,但部分图标(如触摸键盘)暂未提供直接属性,仍需配合注册表读取

批处理实现(基于注册表)

若需用批处理脚本,可参考以下代码:

@echo off
setlocal enabledelayedexpansion

:: 定义注册表路径和键
set "regPath=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"

:: 查询Location状态
reg query "%regPath%" /v "ShowLocationButton" >nul 2>&1
if !errorlevel! equ 0 (
    for /f "tokens=3" %%a in ('reg query "%regPath%" /v "ShowLocationButton"') do (
        set "locationStatus=已开启"
        if %%a equ 0 set "locationStatus=已关闭"
    )
) else (
    set "locationStatus=已关闭"
)

:: 查询Action Center状态
reg query "%regPath%" /v "TaskbarMn" >nul 2>&1
if !errorlevel! equ 0 (
    for /f "tokens=3" %%a in ('reg query "%regPath%" /v "TaskbarMn"') do (
        set "actionCenterStatus=已开启"
        if %%a equ 0 set "actionCenterStatus=已关闭"
    )
) else (
    set "actionCenterStatus=已关闭"
)

:: 查询Touch Keyboard状态
reg query "%regPath%" /v "ShowTouchButton" >nul 2>&1
if !errorlevel! equ 0 (
    for /f "tokens=3" %%a in ('reg query "%regPath%" /v "ShowTouchButton"') do (
        set "touchKeyboardStatus=已开启"
        if %%a equ 0 set "touchKeyboardStatus=已关闭"
    )
) else (
    set "touchKeyboardStatus=已关闭"
)

:: 输出结果
echo Location: !locationStatus!
echo Action Center: !actionCenterStatus!
echo Touch Keyboard: !touchKeyboardStatus!
endlocal

内容的提问来源于stack exchange,提问作者Makoto Aizen Sagara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 08:48:12