本文目录导读:

我来介绍几种控制通知区域(系统托盘)图标的脚本方法:
Windows PowerShell 脚本
显示/隐藏系统图标
# 使用注册表控制系统图标显示 # 导航到图标设置 $path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" # 隐藏时钟 Set-ItemProperty -Path $path -Name "HideClock" -Value 1 # 显示时钟 Set-ItemProperty -Path $path -Name "HideClock" -Value 0 # 隐藏音量图标 Set-ItemProperty -Path $path -Name "HideVolumeControl" -Value 1 # 强制刷新资源管理器 Stop-Process -Name explorer -Force Start-Process explorer
自定义应用图标显示
# 设置特定应用图标隐藏/显示 $appName = "YourApp.exe" $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify" $valueName = "IconStreams" # 需要重启资源管理器才能生效 Restart-Process -Name explorer
AutoHotkey 脚本
控制托盘图标
; 显示/隐藏特定程序图标
SetTrayIcon:
; 隐藏特定应用图标
WinHide, ahk_exe app.exe
; 等待1秒后显示
Sleep, 1000
WinShow, ahk_exe app.exe
return
; 定时轮换托盘图标
#Persistent
SetTimer, ToggleIcon, 5000
ToggleIcon:
; 这里可以编写控制图标的逻辑
return
管理托盘程序
; 快速隐藏多余图标
^+h::
; 隐藏所有非活跃图标
WinHide, ahk_class Shell_TrayWnd
Sleep, 500
WinShow, ahk_class Shell_TrayWnd
return
Python 脚本
使用 pywin32 控制
import win32api
import win32con
import ctypes
import winreg
def control_tray_icon(show_clock=True, show_volume=True):
"""控制Windows系统托盘图标"""
try:
# 修改注册表
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer",
0, winreg.KEY_WRITE
)
# 设置时钟显示
winreg.SetValueEx(key, "HideClock", 0, winreg.REG_DWORD, 0 if show_clock else 1)
# 设置音量显示
winreg.SetValueEx(key, "HideVolumeControl", 0, winreg.REG_DWORD, 0 if show_volume else 1)
winreg.CloseKey(key)
# 重启资源管理器使更改生效
os.system("taskkill /f /im explorer.exe")
os.system("start explorer.exe")
return True
except Exception as e:
print(f"Error: {e}")
return False
# 使用示例
control_tray_icon(show_clock=True, show_volume=True)
批处理脚本 (.bat)
@echo off
rem 控制通知区域图标
echo === 系统托盘图标控制 ===
echo 1. 显示所有图标
echo 2. 隐藏所有图标
echo 3. 只显示时钟
echo 4. 恢复默认
set /p choice=请选择操作(1-4):
if "%choice%"=="1" (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideClock /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideVolumeControl /t REG_DWORD /d 0 /f
echo 已显示所有图标
) else if "%choice%"=="2" (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideClock /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideVolumeControl /t REG_DWORD /d 1 /f
echo 已隐藏所有图标
) else if "%choice%"=="3" (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideClock /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideVolumeControl /t REG_DWORD /d 1 /f
echo 已只显示时钟
) else if "%choice%"=="4" (
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideClock /f 2>nul
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v HideVolumeControl /f 2>nul
echo 已恢复默认设置
)
rem 重启资源管理器
taskkill /f /im explorer.exe
start explorer.exe
echo 操作完成!
pause
JavaScript (Node.js) 脚本
const { exec } = require('child_process');
const path = require('path');
// 控制通知区域图标
function controlTrayIcons(action) {
const cmd = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" /v HideClock /t REG_DWORD /d ${action === 'hide' ? 1 : 0} /f`;
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.error(`执行出错: ${error}`);
return;
}
// 重启资源管理器
exec('taskkill /f /im explorer.exe && start explorer.exe', (err) => {
if (err) {
console.error(`重启资源管理器失败: ${err}`);
return;
}
console.log('通知区域设置已更新');
});
});
}
// 使用
controlTrayIcons('show'); // 或 'hide'
VBScript 控制隐藏托盘图标
' 控制托盘图标显示
Option Explicit
Dim shell
Set shell = CreateObject("WScript.Shell")
' 隐藏时钟
shell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\HideClock", 1, "REG_DWORD"
' 隐藏音量
shell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\HideVolumeControl", 1, "REG_DWORD"
' 重启资源管理器
shell.Run "taskkill /f /im explorer.exe", 0, True
shell.Run "explorer.exe", 0, False
MsgBox "托盘图标设置完成!", vbInformation, "成功"
注意事项
- 权限要求:某些操作需要管理员权限
- 重启资源管理器:大部分更改需要重启资源管理器才生效
- 备份注册表:修改前建议备份注册表
- 兼容性:不同Windows版本可能有差异
选择适合你需求的脚本类型即可,如果需要更具体的控制(如针对特定应用),可以告诉我具体需求。