Windows 10 1903에서 바로가기를 통해 Bluetooth를 켜고 끄는 방법

Windows 10 1903에서 바로가기를 통해 Bluetooth를 켜고 끄는 방법

1) 액션 센터 열기, 2) 블루투스 아이콘 클릭 과정을 바로가기로 에뮬레이트하고 싶습니다.

내 해결책은 AHK를 사용하여 키보드 단축키를 .bat 실행에 매핑하는 것이었습니다. 여기에는 여기에 제안된 스크립트가 포함되어 있습니다.질문.

하지만 제안된 서비스는 트레이 바에 있는 마법의 작은 파란색 블루투스 아이콘을 활성화/제거하지 않습니다.여기에 이미지 설명을 입력하세요

알림 센터에서 블루투스 아이콘을 클릭하면 켜지는 모든 블루투스 서비스를 찾아보고 제안을 통해 활성화했지만 .bat여전히 작동하지 않습니다.

BluetoothUserService_182d916
bthserv
BthHFSrv  
BthHFEnum  
BthEnum   
BthHFAud
BthEnum
BthA2dp
Microsoft_Bluetooth_AvrcpTransport

모든 서비스는 다음과 같습니다. 여기에 이미지 설명을 입력하세요 여기에 이미지 설명을 입력하세요

내 스크립트(위에 언급된 모든 서비스로 Microsoft_Bluetooth_AvrcpTransport를 대체했습니다):

@echo off

for /F "tokens=3 delims=: " %%H in ('sc query "Microsoft_Bluetooth_AvrcpTransport" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "Microsoft_Bluetooth_AvrcpTransport"
  ) else if /I "%%H" NEQ "STOPPED" (
   net stop "Microsoft_Bluetooth_AvrcpTransport"
  )
)

@pause

답변1

먼저.아크Powershell을 시작하는 바로 가기:

#b::
Run, C:\Users\user\Desktop\bluetooth.ps1,,Hide 
return

그런 다음 Powershell을 만듭니다.

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 ($bluetooth.state -eq 'On') {$BluetoothStatus = 'Off'} else {$BluetoothStatus = 'On'}
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null

모든 크레딧은@벤 N그리고@스콧 히스


이 스크립트는 VScode에서 시작할 때, Powershell에 복사하여 붙여넣을 때, 또는 cmd를 사용하여 시작할 때 작동합니다. 하지만 두 번 클릭하거나 .ahk. 해결 방법은 .bat다음을 사용하여 파일을 만드는 것이었습니다.

Run, C:\Users\user\Desktop\bluetooth.ps1,,Hide

그런 다음 이것을 .batahk로 호출하세요.

답변2

AutoHotkey v2.0에는 명령문을 함수로 대체하는 새로운 구문이 도입되었으므로 허용되는 답변은 더 이상 복사하여 붙여넣는 솔루션이 아닙니다.

Windows 10.0.19045에서 AutoHotkey v2.0을 사용하여 이 작업을 수행하려면 다음을 생성해야 했습니다.

  1. 토글-bluetooth.ahk
#b::
{
    Run( 'C:\Users\<user>\Documents\AutoHotkey\toggle-bluetooth.bat', , 'Hide' )
    return
}

(서명에서는 #b::Win+B 단축키를 이 기능에 할당합니다.AHK 문서표기법에 대한 자세한 내용을 참조하세요.)

  1. 토글-bluetooth.bat
powershell.exe -ExecutionPolicy Bypass -File toggle-bluetooth.ps1
  1. 토글-bluetooth.ps1
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 ($bluetooth.state -eq 'On') {$BluetoothStatus = 'Off'} else {$BluetoothStatus = 'On'}
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null

.bat다른 접근 방식에서는 중개인으로 사용하는 것이 필요하지 않을 가능성이 매우 높습니다 . 하지만 이것이 내가 일할 수 있는 유일한 방법이었습니다.

이 솔루션을 개발한 @MagTun 및 @rokdd에게 감사드립니다.

답변3

Bluetooth 트레이바 아이콘을 제거하기 위해 이러한 서비스를 중지/시작할 필요가 없습니다.

아이콘 표시는 꺼짐 및 켜짐 값을 갖는 HKEY_CURRENT_USER\Control Panel\BluetoothDWORD 값에 따라 레지스트리 키에서 제어됩니다. 이를 적용하려면 Explorer를 다시 시작해야 합니다.Notification Area Icon01

다음 두 .bat파일이 작업을 수행합니다.

Bluetooth 알림 영역 아이콘 비활성화

REG ADD "HKCU\Control Panel\Bluetooth" /V "Notification Area Icon" /T REG_DWORD /D 00000000 /F
taskkill /f /im explorer.exe
start explorer.exe

Bluetooth 알림 영역 아이콘 활성화

REG ADD "HKCU\Control Panel\Bluetooth" /V "Notification Area Icon" /T REG_DWORD /D 00000001 /F
taskkill /f /im explorer.exe
start explorer.exe

관련 정보