Created
January 16, 2020 20:33
-
-
Save nefarius/d70c62035539454f5a251d06237ad176 to your computer and use it in GitHub Desktop.
PowerShell snippet to check for presence of a Bluetooth radio using P/Invoke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -TypeDefinition @" | |
namespace PInvoke { | |
using System; | |
using System.Runtime.InteropServices; | |
[StructLayout(LayoutKind.Sequential)] | |
public struct BLUETOOTH_FIND_RADIO_PARAMS | |
{ | |
public UInt32 dwSize; | |
public void Init() | |
{ | |
this.dwSize = (UInt32)Marshal.SizeOf(typeof(BLUETOOTH_FIND_RADIO_PARAMS)); | |
} | |
} | |
public static class BluetoothApis | |
{ | |
[DllImport("BluetoothApis.dll", SetLastError=true)] | |
public static extern IntPtr BluetoothFindFirstRadio(ref BLUETOOTH_FIND_RADIO_PARAMS pbtfrp, out IntPtr phRadio); | |
} | |
} | |
"@; | |
$pbtfrp = New-Object PInvoke.BLUETOOTH_FIND_RADIO_PARAMS | |
$pbtfrp.Init() | |
$phRadio = [System.IntPtr]::Zero | |
exit ([PInvoke.BluetoothApis]::BluetoothFindFirstRadio([ref] $pbtfrp, [ref] $phRadio) -eq [System.IntPtr]::Zero) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment