Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
"log"
"time"
"golang.org/x/sys/windows/registry"
)
func main() {
//Open the key
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `HARDWARE\\DEVICEMAP\\SERIALCOMM`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer k.Close()
//Get the key info
ki, err := k.Stat()
if err != nil {
log.Fatal(err)
}
fmt.Printf("SubkeyCount: %d ValueCount: %d\n", ki.SubKeyCount, ki.ValueCount)
//Get the value count
s, err := k.ReadValueNames(int(ki.ValueCount))
if err != nil {
log.Fatal(err)
}
kvalue := make([]string, ki.ValueCount)
//List all the string value
for i, test := range s {
q, _, err := k.GetStringValue(test)
if err != nil {
log.Fatal(err)
}
kvalue[i] = q
}
fmt.Printf("%s \n", kvalue)
time.Sleep(1000 * time.Millisecond)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment