shirou / gopsutil

psutil for golang
Other
10.56k stars 1.58k forks source link

Windows get disk serial number #1062

Open LYF123123 opened 3 years ago

LYF123123 commented 3 years ago

Like the title, gopsutil now don not support though "GetDiskSerailNumber" to get disk serial number on windows

Lomanic commented 3 years ago

https://github.com/shirou/gopsutil/pull/541#issuecomment-401195949 on how to do that

https://github.com/shirou/gopsutil/issues/435 was auto-closed by #541 being merged, but this PR was then reverted and the issue not reopened.

yuancpfive commented 3 years ago

I also encountered the same problem, after I read the #541 , I don't know how to get disk sn finally, I can't find the method disk.GetDiskSerialNumber and no demo show me how to get it, and IOCountersStat in each name print empty serial number.

yuancpfive commented 3 years ago

after run the code below, I can get disk name, but can't get disk serial number.

mapCountStats, err := disk.IOCounters("")
if err != nil {
    fmt.Printf("disk IOCounters err: %v\n", err)
    return
}
for k, v := range mapCountStats {
    fmt.Printf("key: %v, name:%v, serialNum:%v\n", k, v.Name, v.SerialNumber)
}

the output is this:

key: D:, name:D:, serialNum:
key: E:, name:E:, serialNum:
key: F:, name:F:, serialNum:
key: C:, name:C:, serialNum:

and serialNum is empty, is there are something wrong with my code? please give me some suggestions, thanks a lot.