Forked from a46554/gist:0902d4bf5f1b623f123d80f74d26d659
Created
April 12, 2019 03:37
-
-
Save Jimmy-Xu/d7cdde841f93ccdaa28b992d86ef80c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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