blob: 9f2b81dffc547de29b8d72624f20b941fd0c8836 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
using System;
using System.Management;
using System.Collections.Generic;
namespace grapher.Models.Devices
{
class DeviceList
{
public static List<Tuple<string, string>> GetDeviceHardwareIDs(string PNPClass = "Mouse")
{
var results = new List<Tuple<string, string>>();
ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity"));
foreach (ManagementObject obj in searcher.Get())
{
if (obj["PNPClass"] != null && obj["PNPClass"].ToString() == PNPClass && obj["HardwareID"] != null)
{
String[] hwidArray = (String[])(obj["HardwareID"]);
if (hwidArray.Length > 0)
{
String hwid = hwidArray[0].ToString();
String name = obj["Name"].ToString();
results.Add(Tuple.Create(name, hwid));
}
}
}
return results;
}
}
}
|