Ho difficoltà a leggere una chiave di registro creata dal mio software. Tuttavia con lo stesso codice, sono in grado di leggere altre chiavi.winreg.OpenKey genera un errore di filerotazione per le chiavi di registro esistenti
installdir = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Types"
) #this works perfect
#installdir1 = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
"SOFTWARE\\MySoftware\\MyEvent\\IS"
) #this gives Filenotfound error
# list values owned by this registry key
try:
i = 0
while 1:
name, value, type = winreg.EnumValue(installdir, i)
print (repr(name))
i += 1
except WindowsError:
print ("Bot donf")
value, type = winreg.QueryValueEx(installdir, "10")
print("user is", repr(value))
value, type = winreg.QueryValueEx(winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS"), "v2")
print("user is", repr(value))
Traceback mostra
Traceback (most recent call last):
File "D:/python_scripts/myclass.py", line 32, in <module>
value, type = winreg.QueryValueEx(winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\MySoftware\\MyEvent\\IS"), "v2")
FileNotFoundError: [WinError 2] The system cannot find the file specified
reg query Tuttavia Windows è in grado di recuperare il valore impostato.
#reg query HKLM\SOFTWARE\MySoftware\MyEvent\IS /v v2
HKEY_LOCAL_MACHINE\SOFTWARE\MySoftware\MyEvent\IS
v2 REG_DWORD 0x12
Qualsiasi aiuto sarà molto apprezzato
modificato l'errore nell'istruzione query req. Ma questo non dovrebbe comunque essere un problema. – Debianeese