如何绕过管理员权限从 Python 执行 shell 命令?

How to execute shell commands from Python bypassing Admin rights?

我想在 运行 我的 Python 代码时停止和/或启动服务。但是,除非我 运行 cmd 作为管理员,否则我不能这样做。我该如何解决这个问题?

p1 = subprocess.run(['sc', 'start', 'AdobeARMservice'], shell=True, text=True, capture_output=True)
print(p1.stdout)

Output: [SC] StartService: OpenService FAILED 5: Access is denied.

您可以使用 sudo 运行 python 脚本或授予该用户 运行 启动该服务的权限。