-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
56 lines (44 loc) · 1.62 KB
/
registry.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package lxrunoffline
import (
"errors"
"golang.org/x/sys/windows/registry"
)
func (lx *LxRunOffline) GetRegistryValue(path string, value string) (v string, vtype uint32, err error) {
k, err := registry.OpenKey(registry.CURRENT_USER, registry_path+path, registry.SZ)
if err != nil {
return "", 0, errors.New("Can't OpenKey " + value + err.Error())
}
defer k.Close()
value_string, value_type, err := k.GetStringValue(value)
if err != nil {
return "", value_type, errors.New("Can't GetStringValue " + value + err.Error())
}
return value_string, value_type, nil
}
func (lx *LxRunOffline) GetRegistryValueInt(path string, value string) (v uint64, vtype uint32, err error) {
k, err := registry.OpenKey(registry.CURRENT_USER, registry_path+path, registry.ALL_ACCESS)
if err != nil {
return 0, 0, errors.New("Can't OpenKey " + value + err.Error())
}
defer k.Close()
value_int, value_type, err := k.GetIntegerValue(value)
if err != nil {
return 0, value_type, errors.New("Can't GetIntegerValue " + value + err.Error())
}
return value_int, value_type, nil
}
func (lx *LxRunOffline) GetRegistrySubkey(path string, value string) (v []string, err error) {
k, err := registry.OpenKey(registry.CURRENT_USER, path, registry.ENUMERATE_SUB_KEYS)
if err != nil {
return []string{""}, errors.New("Can't OpenKey " + value + err.Error())
}
defer k.Close()
values, err := k.ReadSubKeyNames(0)
if err != nil {
return []string{""}, errors.New("Can't ReadSubKeyNames " + value + err.Error())
}
return values, nil
}
func addPathPrefix(str string) string {
return str + "\\"
}