24 lines
586 B
Go
24 lines
586 B
Go
// +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
|
|
}
|