2. using System.Management;
3. ใช้ coding ดังนี้
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity where Name like '%Smart Card%'"))
{
collection = searcher.Get();
}
foreach (var device in collection)
{
try
{
var deviceName = (string)device.GetPropertyValue("Name");
if (deviceName.Contains("Smart Card"))
{
//เมื่อ detect เจอว่ามี Smart Card เชื่อมต่ออยู่ ก็ทำงาน blah blah blah
}
}
catch (Exception ex) { }
}
collection.Dispose();
Win32_PnPEntity คือ Plug and Play ซึ่งรวมพวก USB และอุปกรณ์อื่นๆด้วย ถ้าอยากเจาะจงเฉพาะที่เป็น USB ก็ใช้ Win32_USBHub
นอกจากนี้ยังมี Win32_XXXX อีกหลายตัวให้เลือกใช้ อ่านเพิ่มเติมได้ที่นี่ครับ https://msdn.microsoft.com/en-us/librar ... s.85).aspx