【问题标题】:How to execute shell commands from Python bypassing Admin rights? [duplicate]如何绕过管理员权限从 Python 执行 shell 命令? [复制]
【发布时间】:2020-11-19 05:01:03
【问题描述】:

我想在运行 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.

【问题讨论】:

  • 与从 shell 执行此操作的方式相同:使用 sudo
  • @Barmar 好的,所以忘了在 Windows 中提及我,但我认为它是 runas?
  • 可能吧,我不懂windows
  • 如果他们可以轻松绕过管理员权限,那么所有发明的病毒都会这样做。
  • 是的,看来runas /noprofile /user:Administrator cmd 成功了。它就像 Windows 的 sudo。谢谢。

标签: python shell subprocess


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 2011-11-29
    • 2018-04-06
    • 1970-01-01
    相关资源
    最近更新 更多