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. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?2. 前端 - 类到底该如何去命名 .newsList 这种的命名难道真的不是过度语义化吗?~3. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?4. golang - 用IDE看docker源码时的小问题5. docker api 开发的端口怎么获取?6. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题7. docker容器呢SSH为什么连不通呢?8. docker start -a dockername 老是卡住,什么情况?9. python - pyspider 运行 和 age 参数问题?10. MySQL分表之后如何做排序的问题

网公网安备