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 for Mac 創建的dnsmasq容器連不上/不工作的問題2. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””3. 我何時應該在Java中使用JFrame.add(component)和JFrame.getContentPane()。add(component)4. docker - 如何修改運行中容器的配置5. docker鏡像push報錯6. html5和Flash對抗是什么情況?7. javascript - 請指條明路,angular的$event,在select中卻是undefined?8. 利用IPMI遠程安裝centos報錯!9. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????10. phpstudy8.1沒集成mysql-front

網公網安備