# ================================ # Monitor Bluetooth – wyłącza gdy nie używany # Wymaga uruchomienia jako Administrator # ================================ Add-Type -AssemblyName System.Windows.Forms # Sprawdza czy jest włączony adapter Bluetooth (radio) function Test-BluetoothActive { $radio = Get-PnpDevice -Class Bluetooth | Where-Object { $_.Status -eq 'OK' -and ($_.InstanceId -match 'BTH\\MS_RR' -or $_.Name -match 'Bluetooth') } return ($null -ne $radio) } # Zatrzymuje wszystkie usługi Bluetooth (również te z losowymi suffixami) function Stop-AllBluetoothServices { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Zatrzymywanie usług Bluetooth..." # Klasyczne usługi Stop-Service -Name bthserv -Force Stop-Service -Name BTAGService -Force Stop-Service -Name BthAvctpSvc -Force # Nowe usługi z losowymi suffixami (działają od Win11 22H2+) Get-Service -Name "BluetoothUserService_*" | Stop-Service -Force Get-Service -Name "DevicesFlowUserSvc_*" | Stop-Service -Force Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Wszystkie usługi Bluetooth zatrzymane." } # Sprawdzenie uprawnień administratora if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { [System.Windows.Forms.MessageBox]::Show( "Uruchom ten skrypt jako Administrator!", "Brak uprawnień", "OK", "Error" ) exit } Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Monitor Bluetooth uruchomiony – sprawdzam co 30 sekund." # Główna pętla – działa bez końca while ($true) { if (Test-BluetoothActive) { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Bluetooth jest włączony i używany – czekam." } else { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Bluetooth wyłączony lub brak urządzeń → zatrzymuję usługi." Stop-AllBluetoothServices # Opcjonalnie: możesz też całkowicie wyłączyć kartę Bluetooth # Get-PnpDevice -Class Bluetooth | Where-Object {$_.Status -eq 'OK'} | Disable-PnpDevice -Confirm:$false [System.Windows.Forms.MessageBox]::Show( "Bluetooth nie jest używany.`nWszystkie usługi Bluetooth zostały zatrzymane.", "Bluetooth wyłączony", "OK", "Information" ) | Out-Null } Start-Sleep -Seconds 30 }