我已经尝试了几种方法,但都不起作用。
os.system('net stop service_name')
返回"系统错误5已发生。拒绝访问。
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')
又没发生什么
win32serviceutil.StopService(service_name)
和其他方式
try addnoprofile
:
import os
service_name = ''
action = "stop"
os.system(f'runas /noprofile /user:administrator "net {action} '{service_name}'"')