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. javascript - vue组件通过eventBus通信时,报错a.$on is not a function2. python3.x - python3.5.2安装时make报错求助3. html - vue项目中用到了elementUI问题4. javascript - 在使用 vue.js element ui的时候 怎么样保留table翻页后check的值?5. mysql_replication - mysql读写分离时如果单台写库也无法满足性能怎么解决6. ionic 项目 ionic build android -release 打包时报错7. linux - ubuntu 命令行中文 显示菱形,期望通过引入字体解决而不是zhcon这种方式8. angular.js - 如何控制ngrepeat输出的个数9. mac里的docker如何命令行开启呢?10. python - 如何用pandas处理分钟数据变成小时线?

网公网安备