from winreg import * # Путь в реестре key_my = OpenKey(HKEY_CURRENT_USER, 'SOFTWARE\Microsoft\Windows\\CurrentVersion\Run') # Установить программу "notepad" в автозагрузку SetValueEx(key_my, 'mynotepad', 0, REG_SZ, 'C:\\Windows\\System32\\notepad.exe') # Закрыть реестр CloseKey(key_my) 

I run this script in cmd from the Administrator, but it gives me

PermissionError: [WinError 5] Access is denied.

How do I remove this restriction?

    1 answer 1

    Decision.

     from winreg import * # Путь в реестре key_my = OpenKey(HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 0, KEY_ALL_ACCESS) # Установить программу "notepad" в автозагрузку SetValueEx(key_my, 'mynotepad', 0, REG_SZ, r'C:\Windows\System32\notepad.exe') # Закрыть реестр CloseKey(key_my) 

    In this way, you can program any program, register the script in the registry and, in a specific case, the "notepad" program will start after Windows is loaded.

    • 3
      Try using raw-strings for windows-paths: r'C:\Windows\System32\notepad.exe' - this simplifies writing, eliminating the need to escape the backslash. - Timofei Bondarev