On 2022-05-03 10:31, Nicolas Formichella wrote:
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?
Use 'QueryValue' with an empty string:
value = winreg.QueryValue(key, "")
or None:
value = winreg.QueryValue(key, None)
--
https://mail.python.org/mailman/listinfo/python-list