gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

Windows get disk serial number

Open LYF123123 opened this issue 4 years ago • 3 comments

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

LYF123123 avatar Apr 22 '21 03:04 LYF123123

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.

Lomanic avatar Apr 22 '21 20:04 Lomanic

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 avatar May 29 '21 02:05 yuancpfive

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.

yuancpfive avatar May 31 '21 03:05 yuancpfive