Exemple #1
0
func (self *RegKey) GetValues() ([]string, error) {
	var valueCount uint32
	var maxBuffer uint32
	err := wrappers.RegQueryInfoKey(
		self.handle,
		nil,
		nil,
		nil,
		nil,
		nil,
		nil,
		&valueCount,
		&maxBuffer,
		nil,
		nil,
		nil)
	if err != nil {
		return nil, NewWindowsError("RegQueryInfoKey", err)
	}
	values := make([]string, 0, valueCount)
	buf := make([]uint16, maxBuffer)
	var i uint32
	for i = 0; i < valueCount; i++ {
		size := maxBuffer
		err = wrappers.RegEnumValue(
			self.handle,
			i,
			&buf[0],
			&size,
			nil,
			nil,
			nil,
			nil)
		if err != nil && err != wrappers.ERROR_MORE_DATA {
			return nil, NewWindowsError("RegEnumValue", err)
		}
		values = append(values, syscall.UTF16ToString(buf[0:size]))
	}
	return values, nil
}
Exemple #2
0
func (self *RegKey) GetSubKeys() ([]string, error) {
	var subKeyCount uint32
	var maxBuffer uint32
	err := wrappers.RegQueryInfoKey(
		self.handle,
		nil,
		nil,
		nil,
		&subKeyCount,
		&maxBuffer,
		nil,
		nil,
		nil,
		nil,
		nil,
		nil)
	if err != nil {
		return nil, NewWindowsError("RegQueryInfoKey", err)
	}
	subKeys := make([]string, 0, subKeyCount)
	buf := make([]uint16, maxBuffer)
	var i uint32
	for i = 0; i < subKeyCount; i++ {
		size := maxBuffer
		err = wrappers.RegEnumKeyEx(
			self.handle,
			i,
			&buf[0],
			&size,
			nil,
			nil,
			nil,
			nil)
		if err != nil {
			return nil, NewWindowsError("RegEnumKeyEx", err)
		}
		subKeys = append(subKeys, syscall.UTF16ToString(buf[0:size]))
	}
	return subKeys, nil
}