PowerShell双显示器打开Edge窗口异常问题求助
问题原因分析
- Edge多进程模型限制:当已有Edge实例运行时,新的启动请求会被主进程接管,而非创建完全独立的进程。这会导致后续窗口的位置、全屏参数被主进程的现有状态覆盖——尤其是全屏模式下,Edge会优先沿用第一个窗口的显示配置。
--start-fullscreen参数的全局优先级问题:一旦第一个窗口以全屏启动,后续窗口的该参数会被主进程忽略,强制继承已有窗口的全屏状态。
解决办法
1. 用独立用户配置隔离Edge进程
通过--user-data-dir参数为每个窗口指定独立的临时配置目录,让每个Edge窗口运行在完全独立的进程实例中,彻底避免主进程接管请求。
修改后的脚本示例(两个脚本仅$monitorIndex、$url和$userDataDir不同):
$edgeExePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" $monitorIndex = 0 # 目标显示器索引 $url = "https://www.example.com/" $userDataDir = "$env:TEMP\Edge_Monitor_0" # 独立配置目录 Add-Type -AssemblyName System.Windows.Forms if (Test-Path $edgeExePath) { $screenBounds = [System.Windows.Forms.Screen]::AllScreens[$monitorIndex].Bounds $windowPosition = "$($screenBounds.Left),$($screenBounds.Top)" $windowSize = "$($screenBounds.Width),$($screenBounds.Height)" # 调整参数顺序:先指定独立配置,再设置窗口属性 $edgeArgs = "--user-data-dir=`"$userDataDir`" --new-window --window-position=$windowPosition --window-size=$windowSize --start-fullscreen $url" Start-Process -FilePath $edgeExePath -ArgumentList $edgeArgs } else { Write-Host "Microsoft Edge未安装或路径错误。" }
第二个脚本只需修改$monitorIndex=1、$url="https://www.anotherexample.com/"、$userDataDir="$env:TEMP\Edge_Monitor_1"即可。
2. 验证屏幕索引正确性
先运行以下命令确认屏幕索引和实际显示器的对应关系,避免选错误的显示器:
Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Screen]::AllScreens | ForEach-Object { Write-Host "索引: $($_.DeviceName.Split('\')[-1]) | 位置: $($_.Bounds.Left),$($_.Bounds.Top) | 分辨率: $($_.Bounds.Width)x$($_.Bounds.Height)" }
3. 可选:优化参数顺序
确保--new-window和--user-data-dir在窗口位置、尺寸参数之前,让Edge优先处理独立窗口和配置的逻辑。
注意事项
- 临时配置目录会自动创建,关闭Edge后可手动删除
$env:TEMP下的对应文件夹,避免占用磁盘空间。 - 若仍有问题,可尝试添加
--no-first-run参数跳过首次启动引导,进一步减少进程干扰。
内容的提问来源于stack exchange,提问作者Yamahari
相关产品推荐
相关产品推荐

