| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
//go:build windows |
| 5 |
|
| 6 |
package resource // import "go.opentelemetry.io/otel/sdk/resource" |
| 7 |
|
| 8 |
import ( |
| 9 |
"golang.org/x/sys/windows/registry" |
| 10 |
) |
| 11 |
|
| 12 |
// implements hostIDReader. |
| 13 |
type hostIDReaderWindows struct{} |
| 14 |
|
| 15 |
// read reads MachineGuid from the Windows registry key: |
| 16 |
// SOFTWARE\Microsoft\Cryptography. |
| 17 |
func (*hostIDReaderWindows) read() (string, error) { |
| 18 |
k, err := registry.OpenKey( |
| 19 |
registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Cryptography`, |
| 20 |
registry.QUERY_VALUE|registry.WOW64_64KEY, |
| 21 |
) |
| 22 |
if err != nil { |
| 23 |
return "", err |
| 24 |
} |
| 25 |
defer k.Close() |
| 26 |
|
| 27 |
guid, _, err := k.GetStringValue("MachineGuid") |
| 28 |
if err != nil { |
| 29 |
return "", err |
| 30 |
} |
| 31 |
|
| 32 |
return guid, nil |
| 33 |
} |
| 34 |
|
| 35 |
var platformHostIDReader hostIDReader = &hostIDReaderWindows{} |