-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetDrives.go
50 lines (47 loc) · 1.3 KB
/
getDrives.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
45
46
47
48
49
50
package main
import (
"fmt"
"github.com/StackExchange/wmi"
)
type Win32_DiskDrive struct {
Description string
ConfigManagerErrorCode uint32
DeviceID string
Manufacturer string
Model string
MediaType string
SerialNumber string
Status string
Name string
Size int64
}
func GetDriveDevices() []Device {
var diskDrivesWin32 []Win32_DiskDrive
var diskDrives []Device
err := wmi.Query("SELECT * FROM Win32_DiskDrive", &diskDrivesWin32)
if err != nil {
fmt.Println("Error querying disk drives:", err)
return nil
}
for _, drive := range diskDrivesWin32 {
diskDrives = append(diskDrives, Device{
Name: drive.Model,
Model: drive.Model,
ConfigManagerErrorCode: drive.ConfigManagerErrorCode,
Status: drive.Status,
SerialNumber: drive.SerialNumber,
Description: drive.Description,
DeviceID: drive.DeviceID,
MediaType: drive.MediaType,
Manufacturer: drive.Manufacturer,
Size: drive.Size,
MPU401Address: 0,
PNPDeviceID: "",
})
}
if len(diskDrives) < 1 {
return []Device{}
} else {
return diskDrives
}
}