Exemple #1
0
func RegistryKeyUint32(rootKey *RegistryKey, subKeyPath, valueName string) (value uint32, err error) {
	var hKey win.HKEY
	if win.RegOpenKeyEx(
		rootKey.hKey,
		syscall.StringToUTF16Ptr(subKeyPath),
		0,
		win.KEY_READ,
		&hKey) != win.ERROR_SUCCESS {

		return 0, newError("RegistryKeyUint32: Failed to open subkey.")
	}
	defer win.RegCloseKey(hKey)

	bufSize := uint32(4)

	if win.ERROR_SUCCESS != win.RegQueryValueEx(
		hKey,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&value)),
		&bufSize) {

		return 0, newError("RegQueryValueEx")
	}

	return
}
Exemple #2
0
func listPort() (res []String) {
	var root win.HKEY
	res = make([]string, 0)
	rootpath, _ := syscall.UTF16PtrFromString("HARDWARE\\DEVICEMAP\\SERIALCOMM")
	fmt.Println(win.RegOpenKeyEx(win.HKEY_LOCAL_MACHINE, rootpath, 0, win.KEY_READ, &root))

	var callError int32
	var index uint32 = 0
	for callError == 0 {
		var name_length uint32 = 72
		var key_type uint32
		var lpDataLength uint32 = 72

		name := make([]uint16, 72)
		lpData := make([]byte, 72)

		callError = win.RegEnumValue(root, index, &name[0], &name_length, nil, &key_type, &lpData[0], &lpDataLength)

		output := make([]uint16, 72)

		for i := uint32(0); i < lpDataLength; i = i + 2 {
			fmt.Println(uint16(lpData[i])<<8, "-", lpData[i+1])
			output[i/2] = uint16(lpData[i+1])<<8 + uint16(lpData[i])
		}

		res = append(res, syscall.UTF16ToString(output))
		index++
	}

	win.RegCloseKey(root)

}
Exemple #3
0
func RegistryKeyString(rootKey *RegistryKey, subKeyPath, valueName string) (value string, err error) {
	var hKey win.HKEY
	if win.RegOpenKeyEx(
		rootKey.hKey,
		syscall.StringToUTF16Ptr(subKeyPath),
		0,
		win.KEY_READ,
		&hKey) != win.ERROR_SUCCESS {

		return "", newError("RegistryKeyString: Failed to open subkey.")
	}
	defer win.RegCloseKey(hKey)

	var typ uint32
	var data []uint16
	var bufSize uint32

	if win.ERROR_SUCCESS != win.RegQueryValueEx(
		hKey,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&typ,
		nil,
		&bufSize) {

		return "", newError("RegQueryValueEx #1")
	}

	data = make([]uint16, bufSize/2+1)

	if win.ERROR_SUCCESS != win.RegQueryValueEx(
		hKey,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&typ,
		(*byte)(unsafe.Pointer(&data[0])),
		&bufSize) {

		return "", newError("RegQueryValueEx #2")
	}

	return syscall.UTF16ToString(data), nil
}