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下的nginx壓力測試2. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?3. mac里的docker如何命令行開啟呢?4. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””5. nignx - docker內nginx 80端口被占用6. docker容器呢SSH為什么連不通呢?7. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下8. docker-compose 為何找不到配置文件?9. docker start -a dockername 老是卡住,什么情況?10. angular.js使用$resource服務把數據存入mongodb的問題。

網公網安備