2013-11-26 39 views
0

我正嘗試使用wmi模塊連接到遠程Windows計算機。我正在使用基於此鏈接中的代碼的邏輯 - http://code.activestate.com/recipes/577945-execute-remote-commands-on-windows-like-psexec/通過wmi進行遠程連接無法正常使用多線程

當我孤立地運行此代碼並嘗試連接到一臺機器時,我可以連接,但是,當我運行代碼時在多線程環境中,我得到了以下錯誤之一,但在另一個線程中,我可以成功連接。

這是錯誤 -

2013-11-26 17:26:47,270::Thread-5::6544::Could not connect to machine - <x_wmi: Unexpected COM Error (-2147352567, 
'Exception occurred.', (0, u'SWbemLocator', 
u'Access is denied. ', None, 0, -2147024891), None)> 

這是我的代碼

class ConnectMsToMs(): 
    ''' This class provide the functionality to transfer 
      file b/w windows OS. One can also delete/execute 
      any file on remote computer. ''' 

    def __init__(self, log, ip, 
       username, password,remote_path=r'c:\\test_script'): 
     self.log = log 
     self.ip = str(ip) 
     self.username = str(username) 
     self.password = str(password) 
     self.remote_path = remote_path 

     try: 
      pythoncom.CoInitialize() 
      self.log.thread_log("Establishing connection to %s" % self.ip) 
      self.connection = wmi.WMI(self.ip, user=self.username, 
             password=self.password) 
      self.log.thread_log("Connection established") 
     #except wmi.x_wmi: 
     except Exception,err: 
      self.log.thread_log("Could not connect to machine - %s"%str(err)) 
      raise 

這是在我連接到ConnectMsToMs對象被稱爲結構。 () - > DTC {inherit threading which call run。} - > dba.sanity(){這是一個不同類的函數,這個實習生調用連接} - > connect(){this fn create我的ConnectMsToMs的對象,並嘗試連接到系統}

回答

0

我遇到了同樣的問題,到目前爲止還沒有找到任何有關如何解決方案的信息。

我已經使用Windows程序「遠程桌面」成功連接到本機,所以我知道該服務處於活動狀態並接受來自本機的連接。

我想下面的行

connection = wmi.WMI("192.168.1.5", user="username", password="password") 

導致

x_access_denied: <x_wmi: Unexpected COM Error (-2147352567, 'Exception occurred.', (0, u'SWbemLocator', u'Access is denied. ', None, 0, -2147024891), None)> 
測試