All pastes #1512321 Raw Edit

Anonymous

public text v1 · immutable
#1512321 ·published 2009-07-30 15:32 UTC
rendered paste body
        public static string GetBluetoothPortName(BluetoothAddress deviceaddress)
        {
            string portname = string.Empty;
            long l_deviceaddress = deviceaddress.ToInt64();

            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\Bluetooth\Serial\Ports"))
            {
                foreach (string s_address in rk.GetSubKeyNames())
                {
                    long address = long.Parse(s_address, System.Globalization.NumberStyles.AllowHexSpecifier);

                    if (address == l_deviceaddress)
                    {
                        using (RegistryKey thisrk = rk.OpenSubKey(s_address))
                        {
                            portname = (string)thisrk.GetValue("Port", string.Empty);
                        }
                        break;
                    }
                }
            }

            return portname.TrimEnd(new char[] { '\0', '\n', '\r' });
        }