Set a new REG_MULTI_SZ value?

1.2k Views Asked by At

I'm trying to create a new REG_MULTI_SZ value for a new registry key in python 2.7

This code works great for REG_SZ, REG_DWORD and others using string/int, but I couldn't find the correct value to send for a multi size string.

reg_key = r'Control Panel\Mouse\Moshe'
reg_hkey = _winreg.HKEY_CURRENT_USER

_winreg.CreateKey(reg_hkey, reg_key)
        registry_key = _winreg.OpenKey(reg_hkey, reg_key, 0, _winreg.KEY_WRITE)

_winreg.SetValueEx(registry_key, 'S2', 0, _winreg.REG_MULTI_SZ, <VALUE>)

Whatever I tried resulted in:

Could not convert the data to the specified type

What value should be sent in order for this to work?

(FYI: I even tried to create a REG_MULTI_SZ manually then reading it. I got a tuple of unicodes

(u'Car',u'Bus',u'Train')

I tried sending this and got the same error.)

1

There are 1 best solutions below

0
On

Turns out a list of strings works:

_winreg.SetValueEx(registry_key, 'S2', 0, _winreg.REG_MULTI_SZ, ["Car", "Bus", "Train"])