"Форум на сайте Чагадаева"

Пожалуйста, войдите или зарегистрируйтесь.

Расширенный поиск  

Новости:

16 октября 2008 года 19:40
Оказывается, что в качестве login'а при входе можно использовать e-mail.
Отличная возможность, форуму +100! :)

Автор Тема: [manual, Windows, W8] включение и выключение Bluetooth из командной строки  (Прочитано 3119 раз)

0 Пользователей и 1 Гость просматривают эту тему.

adc

  • Administrator
  • Новичёк
  • *****
  • Сообщений: 430
    • E-mail

Включение/выключение Bluetooth производится с помощью программы BT-Switch.ps1 (написанной на PowerShell)

Переключить Bluetooth: если выключен - включить; если включён - выключить
PowerShell -executionpolicy remotesigned -File BT-Switch.ps1

Включить Bluetooth
PowerShell -executionpolicy remotesigned -File BT-Switch.ps1 -BluetoothStatus On

Выключить Bluetooth
PowerShell -executionpolicy remotesigned -File BT-Switch.ps1 -BluetoothStatus Off


Код: (BT-Switch.ps1) [Выделить]
[CmdletBinding()] Param (
    [Parameter()][ValidateSet('On', 'Off')][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
if (!$BluetoothStatus) { if ($bluetooth.state -eq 'On') { $BluetoothStatus = 'Off' } else { $BluetoothStatus = 'On' } }
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
« Последнее редактирование: 26 Марта 2024 года, 13:23 от adc »
Записан