-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUtil.go
35 lines (30 loc) · 890 Bytes
/
Util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"golang.org/x/sys/windows/registry"
"log"
)
func openRegistryKey(hive registry.Key, path string) registry.Key {
key, _, err := registry.CreateKey(hive, path, registry.ALL_ACCESS)
if err != nil {
log.Fatal(`There was an error opening the registry key: `, err)
}
return key
}
func closeRegistryKey(key registry.Key) {
err := key.Close()
if err != nil {
log.Fatal(`There was an error closing the registry key.`)
}
}
func getRegistryValue(hive registry.Key, path string, value string) (string, uint32, error) {
key := openRegistryKey(hive, path)
retVal, retType, err := key.GetStringValue(value)
closeRegistryKey(key)
return retVal, retType, err
}
func setRegistryValue(hive registry.Key, path string, name string, value string) error {
key := openRegistryKey(hive, path)
err := key.SetStringValue(name, value)
closeRegistryKey(key)
return err
}