python使用wmi实现远程计算机.bat文件调用
问题描述
-- coding: utf-8 --import wmi,jsonimport timelogfile = ’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 Trueexcept Exception,e: log = open(logfile, ’a’) log.write((’%s, call bat Failed!rn’) % ipaddress) log.close() return Falsereturn False
if __name__==’__main__’:
call_remote_bat('ipaddress', 'username', 'password')代码是这样的 为什么会一直成功不了,请哪位高手帮忙看一下
问题解答
回答1:首先先确保有执行的权限,然后再确保你bat中的操作是成功的。
相关文章:
1. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?2. javascript - echart+百度地图3. web - Rails3使用form_for时出现undefined method `*_path’错误。4. css - autoprefixer没有添加web-kit前缀5. 无效的配置对象已使用与API模式不匹配的配置对象初始化了Webpack6. javascript 开发百度地图7. nginx - 关于vue项目部署到ngnix后出现的问题8. angular.js - 百度爬虫如何处理“#”符号?9. nosql - mongodb 多组数据不固定字段查询问题 [百度党请绕道]10. css3 - 请问,如何通过CSS实现高度height随宽度width变化而变化,保持长宽比例不变,宽度是根据父元素宽度变化的?
