
Eu tenho um laptop Win10 que movo entre casa e trabalho. Eu uso mouses Bluetooth idênticos, mas separados, em cada local. Cada vez que troco de local (e, portanto, troco de mouse bluetooth), devo entrar em Configurações para ativar e ligar novamente o "interruptor" do bluetooth para fazer o laptop se conectar ao novo mouse (mesmo que ele apareça como já " emparelhado" na lista de dispositivos Bluetooth). Observe que este é o caso mesmo durante as reinicializações.
É claro que meu primeiro pensamento para automatizar esse processo foi apenas usar um script para devolver o (s) serviço (s) bluetooth no momento da inicialização para emular o desligamento e a ativação novamente do botão Bluetooth na página Configurações. Mas parece que não estou conseguindo identificar o serviço certo (se é que essa é a abordagem certa) para alternar. Eu usei o PowerShell para parar "bthserv" e "ibtsiva", mas meu mouse ainda está funcionando bem, então obviamente isso não equivale a "desligar" o botão Bluetooth.
PS C:\WINDOWS\system32> get-service -DisplayName *Bluetooth*
Status Name DisplayName
------ ---- -----------
Stopped BluetoothUserSe... Bluetooth User Support Service_3b07...
Stopped BTAGService Bluetooth Audio Gateway Service
Stopped bthserv Bluetooth Support Service
Stopped ibtsiva Intel Bluetooth Service
Existe algum outro serviço que eu deveria alternar? Ou o serviço é uma abordagem completamente errada? Forçar o desligamento do hardware e a reinicialização funciona sempre, então definitivamente inclui qualquer ação que eu precise fazer. Eu só preciso encontrar uma maneira de automatizá-lo. Alguma indicação?
Responder1
Veja estas perguntas e respostas…
Ligue/desligue o rádio/adaptador Bluetooth do cmd/powershell no Windows 10
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$BluetoothStatus
)
If ((Get-Service bthserv).Status -eq 'Stopped')
{ Start-Service bthserv }
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() `
| ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType)
{
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
$netTask.Result
}
[Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
[Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
$radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
$bluetooth = $radios | ? { $_.Kind -eq 'Bluetooth' }
[Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null