hotarunx's diary

競プロとゲームをしていません

マルチディスプレイの拡張→セカンドスクリーンを切り替えるPowerShellスクリプトを書いた

スクリプト

古いDisplaySwitch.exeが必要です。

# [DisplaySwitch.exe only opens the menu, regardless of the arguments : windowsinsiders](https://www.reddit.com/r/windowsinsiders/comments/uurnqd/comment/ipeoq15/?utm_source=reddit&utm_medium=web2x&context=3)
Add-Type -AssemblyName System.Windows.Forms
$displayCount = [System.Windows.Forms.Screen]::AllScreens.Count

# 接続中のディスプレイ数を入力
$maxDisplayCount = 4

if ($displayCount -eq $maxDisplayCount) {
    # 拡張→セカンドスクリーンのみ
    C:\Users\hogehoge\script\DisplaySwitch.exe /external
}
else {
    # セカンドスクリーンのみ→拡張
    C:\Users\hogehoge\script\DisplaySwitch.exe /extend
}

EXE化

PS2EXEというソフトでEXE化した。

MScholtes/PS2EXE: Module to compile powershell scripts to executables

ps2exe .\トグルマルチディスプレイ.ps1 -noConsole

実装のコツ

DisplaySwitch.exe only opens the menu, regardless of the arguments : windowsinsiders

  1. DisplaySwitch.exeはアップデートで機能が削減されて、オプションが効かなくなった。
  2. 従来はオプションをつければGUI操作が不要だったが、できなくなった。
  3. 古いDisplaySwitch.exeを手に入れよう。
  4. 古いPCからコピーしてくるかネットで配っているものをダウンロードするといい。