个人需要定时开启关闭蓝牙,遂尝试,目前已成功,网络上资料较少,做记录。
首先,定时执行,需要用到windows10定时任务计划程序。
然后,蓝牙的开关使用powershell控制。
网上看了一圈,好像没有很直接的指令直接开启关闭蓝牙。在外网找到了个解决方案。
新建一个ps1脚本
[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)
$ne