Not able to turn on/off bluetooth radio setting using Win32 API (Bluetoothapis.h)

Jone Selas 81 Reputation points
2021-11-18T06:52:23.53+00:00

I need to turn ON/OFF the Bluetooth radio in Windows 10 settings. I tried the Win32 API - Bluetoothapis.h API in which,

BluetoothGetRadioInfo function => Returns my bluetooth radio name and I could not find any set method there.

BluetoothSetServiceState function => Returns ERROR_SERVICE_DOES_NOT_EXIST error, I am not able to find the particular bluetooth GUID.

I tried both these functions in native C++ & also in C# and I need certain clarifications,

  1. Is there any specific API to change the bluetooth radio settings?
  2. In Bluetoothapis.h API is there any Set method to change the bluetooth radio?
  3. How do I find the Bluetooth service GUID?

https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/

https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothgetradioinfo

https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothsetservicestate

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,426 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,275 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,741 Reputation points
    2021-11-18T08:09:03.863+00:00

    It can be done with Radio class, like in the code posted in this thread
    Capabilities are not needed in a Desktop app

    You must :

    Add reference to C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
    Add reference to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

    and compile as x64 if the OS is x64
    (tested on Windows 10 21H1 64-bit)

    1 person found this answer helpful.