Here's the code I've been using to change the values of keys in the registry:
import winreg
key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, 'AppEvents\\Schemes\\Apps\\.Default\\.Default\\.Current')
winreg.SetValueEx(key, '(Default)', 0, winreg.REG_SZ, '')
key.Close()
I've had no issues with using this on any keys within the registry. For some reason, if the value name is (Default)
, the code above doesn't work. It just inserts another value with the exact same name. This seems weird as no key can have 2 values with the same name.
I'm guessing that the names look exactly the same, but to the registry, they aren't the same name. I'm not sure why this would be, though.
The value you see listed normally as (Default) in the registry does not have a name of "(Default)"
, it has no value name at all, because it's the default value. (The registry viewer is just displaying the text (Default) to indicate what the value means.) You may be able to pass an empty string (""
) or possibly None
as the second argument of SetKeyEx
to write the default value.