2022-01-15

Windows 11 のタスクバーを天に(PowerShell で)

Windows11 ではメニューからタスクバーを天に持ち上げれなくなったので、みんなレジストリを操作して実現している。手順はどこでも手に入るが、以下のページを参照した。

How to Move the Taskbar to the Top in Windows 11 | Tom's Hardware

  1. regedit を開く
  2. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 を開く
  3. Settings を編集し保存する
    • 2 行目を 7A F4 00 00 03 00 00 00 -> 7A F4 00 00 01 00 00 00にする
      • デフォルトの03が下、01が上というわけ
  4. explorer を再起動する
    • コマンドプロンプトで
      1. taskkill /f /im explorer.exe
      2. start explorer.exe

これが PC 変わる度にやるのクソめんどいので、PowerShell でスクリプト化した。 そんなに機会はないけど一々覚えてないので先程のページを見にったりと、とにかくめんどい。

PowerShell 7.2.1 でやった。

$ShowHex = {param ([array]$arr) ($arr | %{[System.Convert]::ToHexString($_)}) -join ' '}
$path = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'
$key = 'Settings'
$org = Get-ItemProperty $path | Select-Object -ExpandProperty $key
$ShowHex.Invoke((,$org))

$new = @() + $org
$new[12] = 0x01
$ShowHex.Invoke((,$new))
Compare-Object $org $new

Set-ItemProperty $path -name $key -Value $new

Stop-Process -Name explorer -Force
## if explorer doesn't restart, start explorer manually.
# Start-Process -Name explorer

万が一失敗してたら $orgSet-ItemProperty して戻す必要があるので、成功(≒ 天にタスクバー)を確認するまで窓を閉じない方が良かろう。 ちゃんと期待の更新ができているか確認するために、レジストリの値を 16 進数に変換して標準出力までしちゃう。

Gist はこちら

おまけ

taskkill は PowerShell で言うところの何か調べたときのページ ↓

What Is The PowerShell Equivalent Of Taskkill | PDQ.com

Okay, I'll be the first to admit it; the name is a little lackluster. Especially when compared to TASKKILL!!!!!! Stop-Process just doesn't carry the same hostile undertones Thankfully, Microsoft at least gave us kill as an alias, so we've got that going for us. Regardless, let's see if it still packs the same task-killing punch.

さて、最初に断っておきますが、このネーミングは少し物足りないですね。特にTASKKILL!!!!!!と比較するとね。 ありがたいことに、Microsoft は少なくともkillという別名をつけてくれました。 ともかく、同じようにタスクを殺すパンチをパックしているかどうか見てみましょう。

こんなん笑うわw