admin 管理员组

文章数量: 887016

安装wmi,直接pip install wmi
需要受控端的ip,账号和密码 即可。

import wmi


def restart_fastapi_service(ipaddress, user, password):
    conn = wmi.WMI(computer=ipaddress, user=user, password=password)

    filename = "C:\\install\\start_up_fastapi.bat"  # 此文件在远程服务器上
    cmd_callbat = r"cmd /c call %s" % filename
    print(cmd_callbat)
    id, value = conn.Win32_Process.Create(CommandLine=cmd_callbat)  # 执行bat文件   Win32_Process.Create
    print(id, value)
    
if __name__ == '__main__':
    restart_fastapi_service(ipaddress="10.174.120.2", user="Administrator", password="123456789")    

本文标签: 脚本 python Windows bat