-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUSBControllers.go
44 lines (42 loc) · 1.37 KB
/
getUSBControllers.go
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
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"github.com/StackExchange/wmi"
)
func GetUSBControllersDevices() []Device {
var devicesWin32PnP []Win32_PNPDevice
var usbcntrlrDevicesWin32 []Win32_PNPDevice
var usbcntrlrDevices []Device
err := wmi.Query("SELECT * FROM Win32_PnPEntity", &devicesWin32PnP)
if err != nil {
fmt.Println("Error querying USB controllers devices:", err)
return nil
}
for _, pnpDevice := range devicesWin32PnP {
if pnpDevice.PNPClass == "USB" {
usbcntrlrDevicesWin32 = append(usbcntrlrDevicesWin32, Win32_PNPDevice{
Name: pnpDevice.Name,
ConfigManagerErrorCode: pnpDevice.ConfigManagerErrorCode,
Status: pnpDevice.Status,
Description: pnpDevice.Description,
DeviceID: pnpDevice.DeviceID,
PNPDeviceID: pnpDevice.PNPDeviceID,
})
}
}
for _, usbcntrlrDevice := range usbcntrlrDevicesWin32 {
usbcntrlrDevices = append(usbcntrlrDevices, Device{
Name: usbcntrlrDevice.Name,
ConfigManagerErrorCode: usbcntrlrDevice.ConfigManagerErrorCode,
Status: usbcntrlrDevice.Status,
Description: usbcntrlrDevice.Description,
DeviceID: usbcntrlrDevice.DeviceID,
PNPDeviceID: usbcntrlrDevice.PNPDeviceID,
})
}
if len(usbcntrlrDevices) < 1 {
return []Device{}
} else {
return usbcntrlrDevices
}
}