Files

23 lines
1.0 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
. (Join-Path $root 'audio.ps1') status
Initialize-JobApi
New-Item -ItemType Directory -Force -Path (Join-Path $root '.runtime\logs') | Out-Null
$job = [AudioJob]::CreateKillOnCloseJob()
try {
$powershell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
$child = Start-ManagedProcess 'power-policy-test' $powershell @('-NoProfile', '-Command', 'Start-Sleep -Seconds 30') $job 'Normal' $false $true
$state = New-Object AudioJob+PowerThrottlingState
$state.Version = 1
if (-not [AudioJob]::GetProcessInformation($child.Handle, 4, [ref]$state, 12)) {
throw "GetProcessInformation failed: $([Runtime.InteropServices.Marshal]::GetLastWin32Error())"
}
if ($state.ControlMask -ne 5 -or $state.StateMask -ne 0) {
throw "Unexpected power policy: ControlMask=$($state.ControlMask), StateMask=$($state.StateMask)"
}
Write-Host 'Per-process power policy applied and verified.'
} finally {
[void][AudioJob]::CloseHandle($job)
}