一、首先安裝python的wmi包
二、遠程調用bat以下:
複製代碼 代碼以下:python
# -*- coding: utf-8 -*- import wmi,json import time logfile = 'logs_%s.txt' % time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime()) #遠程執行bat文件 def call_remote_bat(ipaddress,username,password): try: #用wmi鏈接到遠程服務器 conn = wmi.WMI(computer=ipaddress, user=username, password=password) filename=r"D:\apps\autorun.bat" #此文件在遠程服務器上 cmd_callbat=r"cmd /c call %s"%filename conn.Win32_Process.Create(CommandLine=cmd_callbat) #執行bat文件 print "執行成功!" return True except Exception,e: log = open(logfile, 'a') log.write(('%s, call bat Failed!\r\n') % ipaddress) log.close() return False return False if __name__=='__main__': call_remote_bat(computer="192.168.1.2", user="testuser", password="testpwd")