2023-06-05 08:15:05 +00:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-04-11 09:46:18 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2023-06-05 08:15:05 +00:00
|
|
|
|
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package resource // import "go.opentelemetry.io/otel/sdk/resource"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/sys/windows/registry"
|
|
|
|
)
|
|
|
|
|
2024-09-24 10:26:26 +00:00
|
|
|
// implements hostIDReader
|
2023-06-05 08:15:05 +00:00
|
|
|
type hostIDReaderWindows struct{}
|
|
|
|
|
2024-09-24 10:26:26 +00:00
|
|
|
// read reads MachineGuid from the windows registry key:
|
|
|
|
// SOFTWARE\Microsoft\Cryptography
|
2023-06-05 08:15:05 +00:00
|
|
|
func (*hostIDReaderWindows) read() (string, error) {
|
|
|
|
k, err := registry.OpenKey(
|
|
|
|
registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Cryptography`,
|
|
|
|
registry.QUERY_VALUE|registry.WOW64_64KEY,
|
|
|
|
)
|
2024-09-24 10:26:26 +00:00
|
|
|
|
2023-06-05 08:15:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer k.Close()
|
|
|
|
|
|
|
|
guid, _, err := k.GetStringValue("MachineGuid")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return guid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var platformHostIDReader hostIDReader = &hostIDReaderWindows{}
|