如何在Python中停止作为管理员的Windows服务?

发布于 2025-01-30 07:43:09 字数 480 浏览 2 评论 0原文

我已经尝试了几种方法,但是它们都没有用。

os.system('net stop service_name')

返回“系统错误5发生。访问被拒绝。

os.system('runas /user:Administrator net stop service_name')

没有错误,但什么也

subprocess.Popen(
    ['runas', '/user:Administrator', 'net stop service_name'],
    stdin=subprocess.PIPE
)
process.stdin.write(b'admin_password_here')

发生

win32serviceutil.StopService(service_name)

I already tried a few ways but none of them worked.

os.system('net stop service_name')

which returns "System error 5 has occurred. Access denied.

os.system('runas /user:Administrator net stop service_name')

no errors, but nothing happened

subprocess.Popen(
    ['runas', '/user:Administrator', 'net stop service_name'],
    stdin=subprocess.PIPE
)
process.stdin.write(b'admin_password_here')

again nothing happened

win32serviceutil.StopService(service_name)

and few more ways

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2025-02-06 07:43:09

尝试添加noprofile

import os
service_name = ''
action = "stop"
os.system(f'runas /noprofile /user:administrator "net {action} '{service_name}'"')

try add noprofile:

import os
service_name = ''
action = "stop"
os.system(f'runas /noprofile /user:administrator "net {action} '{service_name}'"')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文