python使用wmi實(shí)現(xiàn)遠(yuǎn)程計(jì)算機(jī).bat文件調(diào)用
問題描述
-- coding: utf-8 --import wmi,jsonimport timelogfile = ’logs_%s.txt’ % time.strftime(’%Y-%m-%d_%H-%M-%S’, time.localtime())
遠(yuǎn)程執(zhí)行bat文件def call_remote_bat(ipaddress,username,password):
try: #用wmi連接到遠(yuǎn)程服務(wù)器 conn = wmi.WMI(computer=ipaddress, user=username, password=password) filename=r'C:abc.bat' #此文件在遠(yuǎn)程服務(wù)器上 cmd_callbat=r'start C:abc.bat' conn.Win32_Process.Create(CommandLine=cmd_callbat) #執(zhí)行bat文件 print '執(zhí)行成功!' 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')代碼是這樣的 為什么會(huì)一直成功不了,請哪位高手幫忙看一下
問題解答
回答1:首先先確保有執(zhí)行的權(quán)限,然后再確保你bat中的操作是成功的。
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.3. docker - 如何修改運(yùn)行中容器的配置4. python3.x - python連oanda的模擬交易api獲取json問題第五問5. nignx - docker內(nèi)nginx 80端口被占用6. css3 - 沒明白盒子的height隨width的變化這段css是怎樣實(shí)現(xiàn)的?7. javascript - webpack熱加載配置不生效8. javascript - QWebEngineView 如何爬 angular 的動(dòng)態(tài)數(shù)據(jù)?9. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類10. java - instance method中 static后的<K>是什么意思?
