问题
I was following this document to create a key/string in windows registry with this code snippet:
package main
import (
    "golang.org/x/sys/windows/registry"
    "log"
)
func main() {
    k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Audio`, registry.QUERY_VALUE)
    if err != nil {
        log.Fatal(err)
    }
    k.SetStringValue("xyz", "blahblah")
    err = k.Close()
    if err != nil {
        log.Fatal(err)
    }
}
but nothing happens, without any errors. Edit (clarification): It doesn't work, in any circumstances.
回答1:
You are opening the key with only the QUERY_VALUE permission, but you also need SET_VALUE in order to successfully call SetStringValue.
You should also be checking the return value on SetStringValue, which would have likely informed you what the problem was.
k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Audio`, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
    log.Fatal(err)
}
if err := k.SetStringValue("xyz", "blahblah"); err != nil {
    log.Fatal(err)
}
if err := k.Close(); err != nil {
    log.Fatal(err)
}
    来源:https://stackoverflow.com/questions/46542609/create-a-registry-key-string-with-go