python编程实现对远程执行bat文件时遇到的错误
问题描述
代码如下
# -*- coding: utf-8 -*-import wmi,jsonimport timeimport tracebackimport syslogfile = ’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:123.bat' #此文件在远程服务器上cmd_callbat = 'start c:123.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!rn’) % ipaddress)log.close()print traceback.print_exc(file=sys.stdout)return False return Falseif __name__==’__main__’: call_remote_bat(ipaddress='192.168.110.110', username='Administrator',password='12345678')报错情况如下: C:Python27python.exe D:/untitled/远程连接.pyTraceback (most recent call last): File 'D:/untitled/Զ������.py', line 11, in call_remote_bat conn = wmi.WMI(computer=ipaddress, user=username, password=password) File 'C:Python27libsite-packageswmi.py', line 1290, in connect handle_com_error () File 'C:Python27libsite-packageswmi.py', line 241, in handle_com_error raise klass (com_error=err)x_access_denied: <x_wmi: Unexpected COM Error (-2147352567, ’xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3’, (0, u’SWbemLocator’, u’u62d2u7eddu8bbfu95eeu3002 ’, None, 0, -2147024891), None)>None
这是什么错误呢,有哪个高手帮忙解答一下,谢谢~
问题解答
回答1:错误提示得很清楚,拒绝访问
回答2:我说说看到的一个错
cmd_callbat = 'start c:123.bat'
回答3:print 'xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3'发生意外。
一个个排除了,要么是连接意外, 先不执行脚本,执行一个最简单的cmd 命令,dir 之类的,看看有没有正确返回。然后,再执行脚本,看看
相关文章:
1. javascript - 移动端自适应2. datetime - Python如何获取当前时间3. atom开始输入!然后按tab只有空格出现没有html格式出现4. javascript - 在 model里定义的 引用表模型时,model为undefined。5. css3 - 这个右下角折角用css怎么画出来?6. apache - 想把之前写的单机版 windows 软件改成网络版,让每个用户可以注册并登录。类似 qq 的登陆,怎么架设服务器呢?7. android - 课程表点击后浮动后边透明可以左右滑动的界面是什么?8. python3.x - c++调用python39. css3 - 没明白盒子的height随width的变化这段css是怎样实现的?10. java - 根据月份查询多个表里的内容怎么实现好?
