Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[winreg] How to access "(Default)" key value?

358 views
Skip to first unread message

Nicolas Formichella

unread,
May 3, 2022, 5:31:25 AM5/3/22
to
Hello,

I am encountering an issue with winreg, I can't figure out how to read the "(Default)" of a registry value

```
def get_chrome_version() -> str:
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as registry:
with winreg.OpenKeyEx(registry, r"Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
access=winreg.KEY_READ) as key:
value, _ = winreg.QueryValueEx(key, "(default)")
return value
```

Taking the example above it raises a FileNotFoundError :

```
Traceback (most recent call last):
File "C:/Users/noulo/dev/py/chromedriver_dl/main.py", line 14, in get_chrome_version
value, _ = winreg.QueryValueEx(key, "(default)")
FileNotFoundError: [WinError 2] The system cannot find the file specified
```

(Trying "Path" instead of "(Default)" works)

Although the value definitely exists as shown by Powershell

```
Get-Item -Path "HKCU:/Software/Microsoft/Windows/CurrentVersion/App Paths/chrome.exe" | Select-Object -ExpandProperty Property
```

Returns :

```
(default)
Path
```

Is this a bug I should report, or if not, what is the way, using winreg, to access the "(Default)" value of a key?

Regards,
Nicolas FORMICHELLA

MRAB

unread,
May 3, 2022, 12:49:42 PM5/3/22
to
Use 'QueryValue' with an empty string:

value = winreg.QueryValue(key, "")

or None:

value = winreg.QueryValue(key, None)
0 new messages