Skip to content

VonSdite/WindowMute

Repository files navigation

WindowMute

WindowMute 用来拦截某个进程新创建或新显示的窗口,并把这些窗口处理成不可见、透明点击穿透,或者直接挪到屏幕外。

文件说明

  • window_mute.ps1: 主脚本
  • find_window.ps1: 用来查目标窗口的进程名、类名、标题
  • run_window_mute.vbs: 隐藏启动 window_mute.ps1

运行环境

  • Windows
  • PowerShell 5.1 或更高版本
  • 允许当前进程通过 -ExecutionPolicy Bypass 运行脚本

快速开始

1. 先找到可疑窗口

如果你已经知道目标进程名,可以先按进程过滤:

powershell -ExecutionPolicy Bypass -File .\find_window.ps1 -ProcessName <进程名>

例如:

powershell -ExecutionPolicy Bypass -File .\find_window.ps1 -ProcessName WeChat

如果你还不确定是谁在蒙屏,也可以先全局扫描大窗口:

powershell -ExecutionPolicy Bypass -File .\find_window.ps1

重点看输出里的这些字段:

  • Process: 进程名
  • Class: 窗口类名
  • Title: 窗口标题
  • Rect: 窗口位置和大小

如果同一个进程里不止一个窗口,建议优先记录 ClassTitle,后面用来精准过滤,避免误伤正常窗口。

2. 直接运行主脚本

最简单的运行方式:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p <进程名>

例如:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat

如果你已经知道蒙版窗口的类名,可以只拦这一类窗口:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -ClassPattern "Overlay|Mask|Qt5152QWindowIcon"

如果你想按标题过滤:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -TitlePattern "护眼|遮罩|overlay"

也可以同时用:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -ClassPattern "Overlay" -TitlePattern "mask"

3. 后台隐藏运行

如果你不想看到 PowerShell 窗口,可以用:

run_window_mute.vbs

使用前先编辑 run_window_mute.vbs,把里面的:

<ProcessName>

替换成真实进程名,例如:

WeChat

注意:

  • vbs 启动后是隐藏后台进程
  • 这种方式没有控制台,所以不能用 Ctrl+C
  • 建议先把 ps1 调试通,再切到 vbs

参数说明

window_mute.ps1 支持这些参数:

  • -p: 必填,目标进程名,比如 WeChatWeChat.exe
  • -l: 日志路径,默认是 D:\mute.txt
  • -Mode: 处理模式,支持 TransparentHideMove
  • -ClassPattern: 用正则匹配窗口类名
  • -TitlePattern: 用正则匹配窗口标题
  • -SweepIntervalMs: 兜底扫描间隔,默认 2000

模式说明

Transparent

默认模式。窗口还存在,但会被设置成全透明并点击穿透。

适合:

  • 想尽量少影响目标程序逻辑
  • 只是不想看到这层蒙版

Hide

直接把窗口隐藏掉。

适合:

  • 透明模式不够干净
  • 目标窗口会抢焦点或仍然有副作用

Move

把窗口挪到屏幕外。

适合:

  • 某些程序对 HideTransparent 反应异常时作为兜底方案

日志

主脚本现在会同时:

  • 写入日志文件
  • 打印到当前终端

默认日志文件是:

D:\mute.txt

如果该盘不存在,可以手动指定:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -l D:\temp\window_mute.txt

退出方式

直接运行 ps1

如果你是直接在控制台里运行:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat

可以直接按:

Ctrl+C

脚本会优雅退出并释放钩子。

vbs 隐藏启动

如果你是通过 run_window_mute.vbs 启动的,因为没有控制台,Ctrl+C 不可用。

可以用下面这条命令定向结束对应脚本进程:

Get-CimInstance Win32_Process |
  Where-Object { $_.Name -eq 'powershell.exe' -and $_.CommandLine -like '*window_mute.ps1*' } |
  ForEach-Object { Stop-Process -Id $_.ProcessId }

也可以在任务管理器里结束对应的 powershell.exe 进程。

建议的使用流程

  1. find_window.ps1 找到目标进程和窗口类名
  2. 先直接运行 window_mute.ps1
  3. 优先尝试 Transparent
  4. 如果效果不理想,再试 Hide
  5. 确认稳定后,再改用 run_window_mute.vbs 后台启动

示例

只拦截某个进程的指定类名窗口:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -ClassPattern "Qt5152QWindowIcon" -Mode Transparent

按标题过滤并使用隐藏模式:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -TitlePattern "遮罩|蒙版" -Mode Hide

降低兜底扫描频率,进一步减少空闲开销:

powershell -NoProfile -STA -ExecutionPolicy Bypass -File .\window_mute.ps1 -p WeChat -SweepIntervalMs 5000

注意事项

  • ClassPatternTitlePattern 都是正则表达式,不是普通包含匹配
  • 如果过滤条件太宽,可能会把目标进程里的正常窗口一起处理掉
  • 如果过滤条件太窄,可能会漏掉动态生成的新窗口
  • Transparent 通常更温和,Hide 更强硬
  • 日志默认写到 D:\mute.txt,如果该盘不存在,请用 -l 改路径

About

拦截window窗口进行隐藏

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors