[winreg] How to access "(Default)" key value?
Nicolas Formichella
nouloug2 at gmail.com
Tue May 3 05:31:13 EDT 2022
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
More information about the Python-list
mailing list