<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="https://forum.yubico.com/feed.php?f=26&amp;t=1328" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2014-03-03T11:27:24+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=26&amp;t=1328</id>
<entry>
<author><name><![CDATA[Tom]]></name></author>
<updated>2014-03-03T11:27:24+01:00</updated>
<published>2014-03-03T11:27:24+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5021#p5021</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5021#p5021"/>
<title type="html"><![CDATA[Re: [SOLVED]Detect programatically the Y in USB-Device-List]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5021#p5021"><![CDATA[
Hi,<br /><br />If you'd like to share you project please post it on the community project board following these rules:<br /><!-- l --><a class="postlink-local" href="http://forum.yubico.com/viewtopic.php?f=8&amp;t=930">viewtopic.php?f=8&amp;t=930</a><!-- l --><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2195">Tom</a> — Mon Mar 03, 2014 11:27 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Richard]]></name></author>
<updated>2014-03-03T10:46:33+01:00</updated>
<published>2014-03-03T10:46:33+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5020#p5020</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5020#p5020"/>
<title type="html"><![CDATA[Re: [QUESTION]Detect programatically the Y in USB-Device-Lis]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5020#p5020"><![CDATA[
THX<br /><br />You might find the following code helpful. You need a Form, inside a GoupBox, 2 Labels and a TextBox.<br />(Keep in mind, it's not production code.) <br />if You insert/remove an USB-&quot;Drive&quot;-Device, the list of removable devices will be updated.<br />if You insert/remove the Yubico, this keyboards-Device' ID will be shown in the Textbox &quot;txtDevices&quot;.<br />The main procedure is 'OnDeviceChange', there you look for NewID OldID which you may ask with .Contains(...<br /><br />Have fun.<br />Richard <br /><br />MS Visual Studio 2010, C#, .NET Framework 4 Client Profile <br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;<br />using System.IO;<br />using System.Management;<br />using System.Runtime.InteropServices;<br /><br /><br /><br />namespace ShowDrives<br />{<br />    public partial class Form1 : Form<br />    {<br /><br />        public struct _myDriveInfo<br />        {<br />            public string _driveletter;<br />            public string _drivelabel;<br />            public string _drivetype;<br />        }<br /><br />        List&lt;_myDriveInfo&gt; _drives = new List&lt;_myDriveInfo&gt;();<br /><br />        List&lt;string&gt; _keyboards = new List&lt;string&gt;();<br />        List&lt;string&gt; _oldKeyboards = new List&lt;string&gt;();<br /><br />        public Form1()<br />        {<br />            InitializeComponent();<br />            RegisterHidNotification();<br />            CheckKeyboardDevice();<br />        }<br /><br />        public void FindDrives()<br />        {<br />            _drives.Clear();<br /><br />            var drives = DriveInfo.GetDrives();<br />            foreach (var drive in drives)<br />            {<br />                if ((drive.IsReady) &amp; (drive.DriveType == DriveType.Removable))<br />                {<br />                    _myDriveInfo MyDriveInfo = new _myDriveInfo();<br />                    MyDriveInfo._driveletter = drive.Name;<br />                    MyDriveInfo._drivelabel = drive.VolumeLabel;<br />                    MyDriveInfo._drivetype = drive.DriveType.ToString();<br />                    _drives.Add(MyDriveInfo);<br />                }<br />            }<br />        }<br /><br />        private void Form1_Load(object sender, EventArgs e)<br />        {<br />            FindDrives();<br />            Int32 TopLoc;<br />            for (int i = 0; i &lt; _drives.Count(); i++)<br />            {<br />                RadioButton rdo = new RadioButton();<br />                rdo.Name = &quot;rdb &quot; + i.ToString();<br />                rdo.AutoSize = true;<br />                rdo.Text = _drives&#91;i&#93;._driveletter + &quot;    Label: '&quot; + _drives&#91;i&#93;._drivelabel + &quot;',    Type: &quot; + _drives&#91;i&#93;._drivetype;<br />                TopLoc = 20 + 30 * i;<br />                rdo.Location = new Point(15, TopLoc);<br />                groupBox1.Height = TopLoc + rdo.Height + 6;<br />                groupBox1.Controls.Add(rdo);<br />            }<br /><br />            lblMessage.Text = &quot;Please select USB-Drive&quot;;<br />            lblMessage.Location = new Point(groupBox1.Left, groupBox1.Top + groupBox1.Height + 15);<br />        }<br /><br /><br />        private void UpdateDriveList()<br />        {<br />            for (int i = 0; i &lt; groupBox1.Controls.Count; i++)<br />            {<br />                RadioButton rdo = (RadioButton)groupBox1.Controls&#91;i&#93;;<br />                rdo.Dispose();<br />            }<br />            groupBox1.Controls.Clear();<br /><br />            FindDrives();<br />            Int32 TopLoc;<br /><br />            for (int i = 0; i &lt; _drives.Count(); i++)<br />            {<br />                RadioButton rdo = new RadioButton();<br />                rdo.Name = &quot;rdb &quot; + i.ToString();<br />                rdo.AutoSize = true;<br />                rdo.Text = _drives&#91;i&#93;._driveletter + &quot;    Label: '&quot; + _drives&#91;i&#93;._drivelabel + &quot;',    Type: &quot; + _drives&#91;i&#93;._drivetype;<br />                TopLoc = 20 + 30 * i;<br />                rdo.Location = new Point(15, TopLoc);<br />                groupBox1.Height = TopLoc + rdo.Height + 6;<br />                groupBox1.Controls.Add(rdo);<br />            }<br />            lblMessage.Location = new Point(groupBox1.Left, groupBox1.Top + groupBox1.Height + 15);<br />        }<br /><br /><br /><br /><br />        protected override void WndProc(ref Message m)<br />        {<br />            switch (m.Msg)<br />            {<br />                case WinAPI.WM_DEVICECHANGE: OnDeviceChange(ref m); break;<br />            }<br />            base.WndProc(ref m);<br />        }<br /><br />        void OnDeviceChange(ref Message msg)<br />        {<br />            int wParam = (int)msg.WParam;<br />            if (wParam == WinAPI.DBT_DEVICEARRIVAL)<br />            {<br />                label1.Text = &quot;USB-Device plugged in&quot;;<br />                //CheckDevice();<br />                CreateOldKeyboardList();<br />                CheckKeyboardDevice();<br />                string NewID = FindMissingElement(_oldKeyboards, _keyboards);<br />                txtDevices.AppendText(NewID + Environment.NewLine);<br />            }<br />            else if (wParam == WinAPI.DBT_DEVICEREMOVECOMPLETE)<br />            {<br />                label1.Text = &quot;USB-Device removed&quot;;<br />                CreateOldKeyboardList();<br />                CheckKeyboardDevice();<br />                string OldID = FindMissingElement(_keyboards, _oldKeyboards);<br />                txtDevices.AppendText(OldID + Environment.NewLine);<br />            }<br />            UpdateDriveList();<br />        }<br /><br />        void RegisterHidNotification()<br />        {<br />            string e = &quot;&quot;;<br />            WinAPI.DEV_BROADCAST_DEVICEINTERFACE dbi = new WinAPI.DEV_BROADCAST_DEVICEINTERFACE();<br />            int size = Marshal.SizeOf(dbi);<br />            dbi.dbcc_size = size;<br />            dbi.dbcc_devicetype = WinAPI.DBT_DEVTYP_DEVICEINTERFACE;<br />            dbi.dbcc_reserved = 0;<br />            dbi.dbcc_classguid = WinAPI.GUID_DEVINTERFACE_HID;<br />            dbi.dbcc_name = 0;<br />            IntPtr buffer = Marshal.AllocHGlobal(size);<br />            Marshal.StructureToPtr(dbi, buffer, true);<br />            IntPtr r = WinAPI.RegisterDeviceNotification(Handle, buffer, WinAPI.DEVICE_NOTIFY_WINDOW_HANDLE);<br />            if (r == IntPtr.Zero)<br />            {<br />                e = WinAPI.GetLastError().ToString();<br />                MessageBox.Show(e);<br />            }<br />        }<br /><br /><br />        void CheckDevice()<br />        {<br />            IntPtr devinfo = WinAPI.SetupDiGetClassDevs(ref WinAPI.GUID_DEVCLASS_KEYBOARD, IntPtr.Zero, IntPtr.Zero, WinAPI.DIGCF_PRESENT);<br />            WinAPI.SP_DEVINFO_DATA devInfoSet = new WinAPI.SP_DEVINFO_DATA();<br />            devInfoSet.cbSize = Marshal.SizeOf(typeof(WinAPI.SP_DEVINFO_DATA));<br />            /*<br />            if (Win32.SetupDiEnumDeviceInfo(devinfo, 0, ref devInfoSet))<br />            { <br />                label1.Text = &quot;keyboard&quot;;<br />            }<br />            */<br />        }<br /><br />        public const int CR_SUCCESS = 0;<br />        &#91;DllImport(&quot;cfgmgr32.dll&quot;)&#93;<br />        public static extern int CM_Get_Device_ID(int DevInst, IntPtr Buffer, int BufferLen, int Flags);<br /><br />        public static string CM_Get_Device_ID(int DevInst)<br />        {<br />            string s = null;<br />            int len = 300;<br />            IntPtr buffer = Marshal.AllocHGlobal(len);<br />            int r = CM_Get_Device_ID(DevInst, buffer, len, 0);<br />            if (r == CR_SUCCESS) s = Marshal.PtrToStringAnsi(buffer);<br />            return s;<br />        }<br /><br />        private void CheckKeyboardDevice()<br />        {<br />            int count = 0;<br />            IntPtr devinfo = WinAPI.SetupDiGetClassDevs(<br />            ref WinAPI.GUID_DEVCLASS_KEYBOARD,<br />            IntPtr.Zero,<br />            IntPtr.Zero,<br />            WinAPI.DIGCF_PRESENT);<br /><br />            WinAPI.SP_DEVINFO_DATA devInfoSet =<br />            new WinAPI.SP_DEVINFO_DATA();<br />            devInfoSet.cbSize =<br />            Marshal.SizeOf(typeof(WinAPI.SP_DEVINFO_DATA));<br /><br />            _keyboards.Clear();<br />                <br />            while (WinAPI.SetupDiEnumDeviceInfo(devinfo, count, ref devInfoSet))<br />            {<br />                count++;<br />                _keyboards.Add(CM_Get_Device_ID(devInfoSet.DevInst));<br />            }<br />            WinAPI.SetupDiDestroyDeviceInfoList(devinfo);<br />        }<br /><br />        private string FindMissingElement(List&lt;string&gt; Stock, List&lt;string&gt; Elements)<br />        {<br />            string result = &quot;&quot;;<br />            foreach (string Element in Elements)<br />            {<br />                if(!(Stock.Contains(Element)))<br />                {<br />                    result = Element;<br />                    break;<br />                }<br />            }<br />            return result;<br />        }<br /><br />        private void CreateOldKeyboardList()<br />        {<br />            _oldKeyboards.Clear();<br />            foreach (string keyboard in _keyboards)<br />            {<br />                _oldKeyboards.Add(keyboard);<br />            }<br />        }<br />    }<br /><br /><br />    class WinAPI<br />    {<br />        public const int  WM_DEVICECHANGE = 0x0219;<br />        public const int  DBT_DEVICEARRIVAL = 0x8000,  DBT_DEVICEREMOVECOMPLETE = 0x8004;<br />        public const int  DEVICE_NOTIFY_WINDOW_HANDLE = 0,  DEVICE_NOTIFY_SERVICE_HANDLE = 1;<br />        public const int  DBT_DEVTYP_DEVICEINTERFACE = 5;<br />        public static Guid GUID_DEVINTERFACE_HID = new  Guid(&quot;4D1E55B2-F16F-11CF-88CB-001111000030&quot;);<br /><br />        &#91;StructLayout(LayoutKind.Sequential)&#93;<br />        public class DEV_BROADCAST_DEVICEINTERFACE<br />        {<br />            public int dbcc_size;<br />            public int dbcc_devicetype;<br />            public int dbcc_reserved;<br />            public Guid dbcc_classguid;<br />            public short dbcc_name;<br />        }<br /><br />        &#91;DllImport(&quot;user32.dll&quot;, SetLastError = true)&#93;<br />        public static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, Int32 Flags);<br /><br />        &#91;DllImport(&quot;kernel32.dll&quot;)&#93;<br />        public static extern int GetLastError();<br /><br />        public const int DIGCF_PRESENT = 2;<br /><br />        public static Guid GUID_DEVCLASS_KEYBOARD = new Guid(&quot;4D36E96B-E325-11CE-BFC1-08002BE10318&quot;);<br /><br />        &#91;DllImport(&quot;setupapi.dll&quot;)&#93;<br />        public static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, IntPtr Enumerator, IntPtr hWndParent, int Flags);<br /><br />        &#91;DllImport(&quot;setupapi.dll&quot;)&#93;<br />        public static extern bool SetupDiEnumDeviceInfo(IntPtr DeviceInfoSet,int Supplies, ref SP_DEVINFO_DATA DeviceInfoData);<br /><br />        &#91;StructLayout(LayoutKind.Sequential)&#93;<br />        public struct SP_DEVINFO_DATA<br />        {<br />            public int cbSize;<br />            public Guid ClassGuid;<br />            public int DevInst;<br />            public int Reserved;<br />        }<br /><br />        &#91;DllImport(&quot;setupapi.dll&quot;, SetLastError = true)&#93;<br />        public static extern bool SetupDiDestroyDeviceInfoList<br />        (<br />             IntPtr DeviceInfoSet<br />        );<br />    }<br /><br />}<br /></div><p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2827">Richard</a> — Mon Mar 03, 2014 10:46 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Tom]]></name></author>
<updated>2014-03-03T09:32:32+01:00</updated>
<published>2014-03-03T09:32:32+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5018#p5018</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5018#p5018"/>
<title type="html"><![CDATA[Re: [QUESTION]Detect programatically the Y in USB-Device-Lis]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5018#p5018"><![CDATA[
Vendor ID <br />Product ID <br /><br />VID &amp; PID<br /><br />0x0110 pure OTP<br />0x0111 OTP+CCID<br />0x0112 pure CCID<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2195">Tom</a> — Mon Mar 03, 2014 9:32 am</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Richard]]></name></author>
<updated>2014-03-03T10:47:04+01:00</updated>
<published>2014-03-01T11:08:36+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5010#p5010</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5010#p5010"/>
<title type="html"><![CDATA[[SOLVED]Detect programatically the Y in USB-Device-List]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1328&amp;p=5010#p5010"><![CDATA[
Hallo to all!<br /><br />I'd like  - in C# - to detect the Yubico in the list of usb-devices on a windows machine. (win 8+)<br />Any idea, how to achieve this (if possible) ? Where do i have do look for? In Keyboards? If so, is there a specific id, which identifies the &quot;keyboard&quot;-stick? On my machine with my key i find &quot;HID\VID_1050&amp;PID_0110\7&amp;5f69bcd&amp;0&amp;0000&quot;. Is there a Yubico-specific part?<br /><br />Thanks<br />Richard<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=2827">Richard</a> — Sat Mar 01, 2014 11:08 am</p><hr />
]]></content>
</entry>
</feed>