您的位置:首頁技術文章
文章詳情頁

python使用wmi實現遠程計算機.bat文件調用

瀏覽:86日期:2022-07-21 17:47:11

問題描述

-- 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中的操作是成功的。

標簽: Python 編程
相關文章:
国产综合久久一区二区三区