반응형
C# USB Serial number, Pnp number, Description 정보 출력
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestUSB_Ver2
{
class USBSerialNumber //USB 정보를 가져와서 출력해주는 클래스
{
public void main(object Main_USB_inter)
{
DataGridView USB_inter = Main_USB_inter as DataGridView; // Form object 상속 받음
USB_inter.Rows.Clear();
// USB 정보 호출
var usbDevices = GetUSBDevices();
int i = 1;
foreach(var usbDevice in usbDevices)
{
USB_inter.Rows.Add(i, usbDevice.DeviceID, usbDevice.PnpDeviceID, usbDevice.Description);
i++;
}
////
}
// USB 정보 가져오는 부분
static List GetUSBDevices()
{
List devices = new List();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
collection = searcher.Get();
foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description")
));
}
collection.Dispose();
return devices;
}
}
class USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
{
this.DeviceID = deviceID;
this.PnpDeviceID = pnpDeviceID;
this.Description = description;
}
public string DeviceID { get; private set; }
public string PnpDeviceID { get; private set; }
public string Description { get; private set; }
}
// USB 정보 가져오는 부분--끝
}
소스 : http://jmoon.co.kr/106 / jmoon1601.tistory.com/106
반응형
'Develop > C#' 카테고리의 다른 글
| 소스 (0) | 2017.05.06 |
|---|---|
| C# 현재 연결되어 있는 IP주소와 MAC주소 가져오기 (0) | 2017.05.06 |
| C# White List로 Mac기반으로 Network adapter 차단, 인터넷 연결 끊기 (0) | 2017.05.06 |
| C# window forms .dll 생성 및 참조 후 .dll파일 디버깅하는 방법 (0) | 2017.05.06 |
| C# Datagridview 여러가지 정렬 방법 (0) | 2017.05.06 |




최근댓글