2

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.

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Just for completeness - using the empty string worked for me. Passing None was failing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.