Beispiel #1
0
func (self *RegKey) GetValueQWORD(valueName string) (uint64, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return 0, NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_QWORD {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return 0, NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	var value uint64
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&value)),
		&size)
	if err != nil {
		return 0, NewWindowsError("RegQueryValueEx", err)
	}
	return value, nil
}
Beispiel #2
0
func (self *RegKey) GetValueString(valueName string) (string, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return "", NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_SZ {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return "", NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	buf := make([]uint16, size/2)
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&buf[0])),
		&size)
	if err != nil {
		return "", NewWindowsError("RegQueryValueEx", err)
	}
	return syscall.UTF16ToString(buf), nil
}
Beispiel #3
0
func (self *RegKey) GetValueBinary(valueName string) ([]byte, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return nil, NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_BINARY {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return nil, NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	value := make([]byte, size)
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		&value[0],
		&size)
	if err != nil {
		return nil, NewWindowsError("RegQueryValueEx", err)
	}
	return value, nil
}