【问题标题】:Python 3_Error "pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')"Python 3_Error "pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')"
【发布时间】:2020-10-30 04:26:00
【问题描述】:

我最近开始在系统自动化方面尝试使用 python。这是我尝试运行以停止服务的代码,但出现错误 pywintypes.error: (5, 'OpenSCManager', 'Access is denied.')。我浏览了一些在线博客和建议,但我似乎不明白它的要点。我们是否需要使用提升访问权限运行它?如果是这样,我们如何进行?

import os 

import win32serviceutil

service = "Windows Update"


win32serviceutil.StopService(service)

提前谢谢大家。

【问题讨论】:

  • 我认为你必须以管理权限运行它

标签: python-3.x windows automation


【解决方案1】:

导入操作系统

导入 win32serviceutil

service = "Windows 更新"

win32serviceutil.StopService(服务)

您似乎想通过 python 停止 Windows 更新。

Windows 更新正在使用系统权限或管理权限(取决于您的操作系统和版本) 在 Windows 10 1803 中,您需要以 管理员权限运行它(.py 文件或 cmd,如果您通过 CMD 使用 Python) 提升访问权限)。

如果它不起作用,您需要通过 Group PolicyRegistry 禁用它。

因为,在 Windows 10 中,如果使用 系统权限,例如 Windows Defender、Windows 更新和 Windows 防火墙

,它们会自动开启
 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

【讨论】:

    猜你喜欢
    • 2019-05-04
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 2022-01-25
    • 2021-01-10
    • 1970-01-01
    相关资源
    最近更新 更多