I have a problem and I don't know how to solve it. There is a code in which I get the result of the found registry (its output) to the terminal. But, I need to write it to a file right away, and not write a command at startup. How can this be solved? Sorry, I'm still new to Python 3. Here's the code and foto of what I don't want to do. Thank you for your help.
from winreg import (
ConnectRegistry,
OpenKey,
KEY_ALL_ACCESS,
EnumValue,
QueryInfoKey,
HKEY_LOCAL_MACHINE,
HKEY_CURRENT_USER
)
def enum_key(hive, subkey:str):
with OpenKey(hive, subkey, 0, KEY_ALL_ACCESS) as key:
num_of_values = QueryInfoKey(key)[1]
for i in range(num_of_values):
values = EnumValue(key, i)
if values[0] == "LangID": continue
print(*values[:-1], sep="\t")
if __name__ == "__main__":
# Connecting to the HKEY_LOCAL_MACHINE hive
with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as hklm_hive:
print("\nCurrent Version/Build Info")
print("-"*50)
enum_key(hklm_hive, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon")