简体   繁体   中英

PermissionError: [WinError 5] Access is denied (Windows Update Disabler)

Im having trouble with my windows update disabler script, whenever i run in in an unelevated shell i get an error PermissionError: [WinError 5] Access is denied but whenever i run with and elevated shell it just closes with no error. What can i do to avoid, or get rid of this error.

import winreg
option = input("Would you like to continue: ")
if option == ('yes'):
    medic = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\WaaSMedicSvc')
    winreg.SetValueEx(medic, 'Start', 0, winreg.REG_SZ, '4')
    medic.Close()
    wua = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\wuauserv')
    winreg.SetValueEx(wua, 'Start', 0, winreg.REG_SZ, '4')
    wua.Close()
if option == ('no'):
    exit()
else:
    print("Input Error")

You run it in an elevated shell. The Services key is protected. You know, you can make a.reg file and feed it directly to regedit . That will automatically ask for elevation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM