telebit/vendor/github.com/denisbrodbeck/machineid/id_windows.go

24 lines
586 B
Go
Raw Normal View History

2020-05-27 09:57:03 +00:00
// +build windows
package machineid
import (
"golang.org/x/sys/windows/registry"
)
// machineID returns the key MachineGuid in registry `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography`.
// If there is an error running the commad an empty string is returned.
func machineID() (string, error) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Cryptography`, registry.QUERY_VALUE|registry.WOW64_64KEY)
if err != nil {
return "", err
}
defer k.Close()
s, _, err := k.GetStringValue("MachineGuid")
if err != nil {
return "", err
}
return s, nil
}