Registry HKLM editing error "WinError 5 - Access Denied"

Whenever I tried to edit the HKLM of registry python spits error “WinError5 Access Denied”. I have an Administrator rights and I checked with it by code itself. I compile the program and run the exe with administrator rights. Still I get the error.
import winreg, ctypes, sys
def is_admin():
return ctypes.windll.shell32.IsUserAnAdmin()
return False
def get_desired_value():
while True:
desired_value = input(“Enter the desired value for FlightSettingsMaxPauseDays (0 to 3650): “)
if desired_value.isdigit() and 0 <= int(desired_value) <= 3650:
return int(desired_value)
print(“Invalid input. Please enter a positive integer between 0 and 3650.”)
def main():
if is_admin():
input(“Now it is running with Admin’s privileges!”)
print(“You dont have any admin rights”)
desired_value = get_desired_value()
reg_path = r"SOFTWARE\avm”
value_name = “days”
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path, 0, winreg.KEY_WRITE)
# Try to get the existing value
existing_value, _ = winreg.QueryValueEx(key, value_name)
print(f"Registry value ‘{value_name}’ already exists. Changing value…”, key)
except FileNotFoundError:
# If the value doesn’t exist, create it
print(f"Registry value ‘{value_name}’ does not exist. Creating…“)
# Set the new value
winreg.SetValueEx(key, value_name, 0, winreg.REG_DWORD, desired_value)
print(f"Registry value ‘{value_name}’ set to ‘{desired_value}’ successfully.”)
except Exception as e:
print(f"Error: {e}")
if name == “main”:

I found some idea. This is due to the Execution Policy of windows. Although I have the Administrative rights and UAC is disabled, I cannot handle the HKLM of registry. To enable it, I issued the command in powershell as ‘Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine’. I wrote down a power shell script and tested it with command prompt as ‘powershell.exe .\avmdisupd.ps1’ and now it works perfect in powershell script. Will check with python program and revert it.