問題はこれ
learn.microsoft.com
けど、Windows11は解消してるようなのですが、どうなの。
で、以下の実装で、コンパのサウンド設定を開いて閉じるスクリプトを書き直したけど、テストしたら解消٩(*´ᗜ`)ㅅ
メモとして、トリガーはロック解除時にスクリプトを実行。実行はpowershellを
設定値を設定>コンパネのサウンド設定を探してあれば終了>無ければサウンド設定を開く>閉じる。
下のコードをコピーして、適当な名前で保存
# コンパネからサウンド設定を呼び出し閉じる
# .\Reset-SoundCpl.ps1 -DelayBeforeReopenSeconds 1 -DelayBeforeFinalCloseSeconds 1
[CmdletBinding()]
param(
[int]$DelayBeforeReopenSeconds = 1, # 再起動までの待機秒数(既定 5)
[int]$DelayBeforeFinalCloseSeconds = 1, # 再起動後に閉じるまでの待機秒数(既定 3)
[switch]$FinalClose = $true # 既定で自動クローズ
)
function Get-SoundCplProcesses {
Get-CimInstance Win32_Process | Where-Object {
$_.Name -in @('rundll32.exe','control.exe') -and
($_.CommandLine -match '(?i)mmsys\.cpl')
}
}
function Stop-SoundCplProcesses {
param([Parameter(Mandatory=$true, ValueFromPipeline=$true)][object[]]$Processes)
process {
foreach ($p in $Processes) {
try {
Stop-Process -Id $p.ProcessId -Force -ErrorAction Stop
Write-Host "Killed PID=$($p.ProcessId) Name=$($p.Name)"
} catch {
Write-Warning "Stop-Process failed for PID=$($p.ProcessId): $_"
}
}
}
}
function Start-SoundCpl {
$cpl = Join-Path $env:WINDIR 'System32\mmsys.cpl'
try {
Write-Host "Starting Sound CPL via rundll32..."
Start-Process -FilePath (Join-Path $env:WINDIR 'System32\rundll32.exe') `
-ArgumentList "shell32.dll,Control_RunDLL `"$cpl`", 0" `
-WindowStyle Normal
} catch {
Write-Warning "rundll32 での起動に失敗:$_ control.exe 経由に切り替えます。"
try {
Start-Process -FilePath (Join-Path $env:WINDIR 'System32\control.exe') `
-ArgumentList "mmsys.cpl" `
-WindowStyle Normal
} catch {
throw "mmsys.cpl の起動に失敗しました:$_"
}
}
}
function Wait-ForNewSoundCpl {
param([int]$TimeoutMs = 3000, [int]$IntervalMs = 200)
$deadline = [DateTime]::UtcNow.AddMilliseconds($TimeoutMs)
while ([DateTime]::UtcNow -lt $deadline) {
$procs = Get-SoundCplProcesses
if ($procs) { return $procs }
Start-Sleep -Milliseconds $IntervalMs
}
return $null
}
# 1) 既存の mmsys.cpl セッションがあれば終了
$existing = Get-SoundCplProcesses
if ($existing) {
Write-Host "Found $(($existing | Measure-Object).Count) Sound CPL process(es). Closing..."
$existing | Stop-SoundCplProcesses
} else {
Write-Host "No existing Sound CPL processes found."
}
# 2) 指定秒数待機
Write-Host "Waiting $DelayBeforeReopenSeconds second(s) before reopen..."
Start-Sleep -Seconds $DelayBeforeReopenSeconds
# 3) 再起動
Start-SoundCpl
# 4)(既定で有効)再度検索して一定時間後に終了
if ($FinalClose) {
Write-Host "Waiting $DelayBeforeFinalCloseSeconds second(s) before final close..."
Start-Sleep -Seconds $DelayBeforeFinalCloseSeconds
$after = Wait-ForNewSoundCpl -TimeoutMs 3000 -IntervalMs 200
if ($after) {
Write-Host "Final close of Sound CPL..."
$after | Stop-SoundCplProcesses
} else {
Write-Host "Sound CPL not found for final close (timeout)."
}
}
で、これをどう起動させるのか。
www.intellilink.co.jp
こちらの記事をオマージュし、記事中のStartPs1.vbsをそのまま利用
書いてる内容をコピーして、メモ帳に張り付けて保存。
タスクスケジューラを起動して、新規にタスクを作成
トリガータブを開いて、タスクの開始:ワークステーションアンロック時、有効などにしてもらう。
操作タブも開いて新規にて作成し、操作:プログラムの開始、プログラム:wscript.exe。
引数は「//B "C:\apps\StartPs1.vbs" "C:\apps\sound-on.ps1"」先ほど保存したファイルにして閉じる。
画面をロックして、スリープは、PCの設定がそれ用になってないとスリープにならなさそうとか思ったけど、まあ…。
で、無事スリープが出来ましたら、解除して瞬間コンパネのサウンドがちらっと映ったらOK。
おしまい。