Python uses wmi to implement remote computer .bat file calling
巴扎黑
巴扎黑 2017-05-18 10:48:37
0
1
1038

-- 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"C:\abc.bat"   #此文件在远程服务器上
    cmd_callbat=r"start C:\abc.bat"
    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("ipaddress", "username", "password")


代码是这样的  为什么会一直成功不了,请哪位高手帮忙看一下
巴扎黑
巴扎黑

reply all(1)
巴扎黑

First make sure you have execution permission, and then make sure the operation in your bat is successful.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template