@@ -34,6 +34,7 @@ def __init__(self, logger, connection, wmi_namespace):
3434 self .__hash = connection .hash
3535 self .__domain = connection .domain
3636 self .__namespace = wmi_namespace
37+ self .__iWbemServices = None
3738 self .__doKerberos = False
3839 self .__aesKey = None
3940 self .__oxidResolver = True
@@ -49,10 +50,13 @@ def __init__(self, logger, connection, wmi_namespace):
4950 self .__dcom = DCOMConnection (self .__addr , self .__username , self .__password , self .__domain ,
5051 self .__lmhash , self .__nthash , self .__aesKey , self .__oxidResolver , self .__doKerberos )
5152
52- iInterface = self .__dcom .CoCreateInstanceEx (wmi .CLSID_WbemLevel1Login ,wmi .IID_IWbemLevel1Login )
53- iWbemLevel1Login = wmi .IWbemLevel1Login (iInterface )
54- self .__iWbemServices = iWbemLevel1Login .NTLMLogin (self .__namespace , NULL , NULL )
55- iWbemLevel1Login .RemRelease ()
53+ try :
54+ iInterface = self .__dcom .CoCreateInstanceEx (wmi .CLSID_WbemLevel1Login ,wmi .IID_IWbemLevel1Login )
55+ iWbemLevel1Login = wmi .IWbemLevel1Login (iInterface )
56+ self .__iWbemServices = iWbemLevel1Login .NTLMLogin (self .__namespace , NULL , NULL )
57+ iWbemLevel1Login .RemRelease ()
58+ except Exception as e :
59+ self .__logger .error (e )
5660
5761 def query (self , query ):
5862
@@ -61,16 +65,15 @@ def query(self, query):
6165 if query [- 1 :] == ';' :
6266 query = query [:- 1 ]
6367
64- try :
68+ if self .__iWbemServices :
69+
6570 iEnumWbemClassObject = self .__iWbemServices .ExecQuery (query .strip ('\n ' ))
6671 self .__logger .success ('Executed specified WMI query' )
6772 self .printReply (iEnumWbemClassObject )
6873 iEnumWbemClassObject .RemRelease ()
69- except Exception as e :
70- traceback .print_exc ()
7174
72- self .__iWbemServices .RemRelease ()
73- self .__dcom .disconnect ()
75+ self .__iWbemServices .RemRelease ()
76+ self .__dcom .disconnect ()
7477
7578 def describe (self , sClass ):
7679 sClass = sClass .strip ('\n ' )
0 commit comments