Python 3_Error "pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')"

Viewed 1170

I recently started experimenting with python on system automation. Here is a code i tried to run for stopping services but i got the error pywintypes.error: (5, 'OpenSCManager', 'Access is denied.'). i went through some online blogs and suggestion, however i dont seem to get the gist of it. Do we need to run it with Elevated access? if so how do we go ahead?

import os 

import win32serviceutil

service = "Windows Update"


win32serviceutil.StopService(service)

Thank You all, in advance.

1 Answers

import os

import win32serviceutil

service = "Windows Update"

win32serviceutil.StopService(service)

It seems you want to stop the Windows Update via python.

Windows update is using Systems Permission or administrative Permission (it depends on your OS and version) In windows 10 1803 you need to run it (.py file or cmd if you are using Python via CMD) with administrative privilege (Elevated access).

If it doesn't work you need to disable it via Group Policy or Registry.

Since, In Windows 10 things automatically turn on if they are using Systems Permission like windows defender, Windows Update and Windows firewall

 Note: System Permission is Higher than the Administrator's permission.
 It can deny and bypass the Administrator's actions and restrictions.
 But System Permission relies on *Group Policy* or *Registry
 In which the Administrator has access in it by default
Related