Wie kann ich Bluetooth über eine Verknüpfung unter Windows 10 1903 ein-und ausschalten

Ich möchte mit einer Verknüpfung den Vorgang von 1) Öffnen des Action Centers und 2) Klicken auf das Bluetooth-Symbol emulieren.

Meine Lösung bestand darin, AHK zu verwenden, um eine Tastenkombination dem Ausführen von a zuzuordnen .bat, das das in dieser Frage vorgeschlagene Skript enthält.

Der vorgeschlagene Dienst aktiviert/entfernt jedoch nicht das magische kleine blaue Symbol des Bluetooth in der Taskleiste.Bildbeschreibung hier eingeben

Habe ich look für alle bluetooth-Dienste, die aktiviert sind, wenn ich im Action Center auf das Bluetooth-Symbol klicke und sie über das vorgeschlagene .bat aktiviert habe, aber immer noch nicht funktioniert.

BluetoothUserService_182d916
bthserv
BthHFSrv  
BthHFEnum  
BthEnum   
BthHFAud
BthEnum
BthA2dp
Microsoft_Bluetooth_AvrcpTransport

Hier sind alle Dienste: geben Sie hier die Bildbeschreibung eingeben Sie hier die Bildbeschreibung ein

Mein Skript (wo ich Microsoft_Bluetooth_AvrcpTransport durch alle oben genannten Dienste ersetzt habe):

@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
Author: MagTun, 2019-10-20

2 answers

Erstelle zuerst ein .ahk Verknüpfung, die eine Powershell startet:

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

Dann erstellst du eine 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

Alle Gutschriften gehen an @Ben N und @Scott Heath


Dieses Skript funktioniert, wenn ich es von VSCode aus starte, wenn ich es in eine Powershell kopiere oder wenn ich es mit einem cmd starte. Aber nicht, wenn ich darauf doppelklicke oder wenn ich es in .ahk starte. Die Problemumgehung bestand darin, eine .bat Datei mit diesem

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

Und dann nenne dies .bat in ahk.

 1
Author: MagTun,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-10-27 17:07:14

Sie müssen diese Dienste nicht anhalten/starten, um Bluetooth loszuwerden traybar-Symbol.

Die Anzeige des Symbols wird im Registrierungsschlüssel gesteuert HKEY_CURRENT_USER\Control Panel\Bluetooth, durch den DWORD-Wert Notification Area Icon dessen Wert 0 für Off und 1 für On ist. Dies erfordert einen Neustart des Explorers, um wirksam zu werden.

Die folgenden zwei .bat Dateien erledigen die Aufgabe.

Deaktivieren Sie das Symbol Bluetooth-Benachrichtigungsbereich

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

Aktivieren Sie den Bluetooth-Benachrichtigungsbereich symbol

REG ADD "HKCU\Control Panel\Bluetooth" /V "Notification Area Icon" /T REG_DWORD /D 00000001 /F
taskkill /f /im explorer.exe
start explorer.exe
 0
Author: harrymc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-10-20 19:54:41