[pywin32-bugs] [ pywin32-Bugs-2052253 ] Problem calling WMI method
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2008-09-03 22:05:07
|
Bugs item #2052253, was opened at 2008-08-14 19:06 Message generated for change (Comment added) made by rupole You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2052253&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Pending Resolution: None Priority: 5 Private: No Submitted By: Ramon Garcia (ramong) Assigned to: Nobody/Anonymous (nobody) Summary: Problem calling WMI method Initial Comment: An exception is issued if a WMI method call is attempted. The following code shows it. wmiservice = Dispatch("WbemScripting.SWbemLocator") wmi = wmiservice.ConnectServer("localhost", "root\cimv2") moniker = r"winmgmts:" \ "{impersonationLevel=impersonate,(Security,Backup)}!\\\\" + \ computer + r"\root\cimv2" wmi = GetObject(moniker) log_files = wmi.ExecQuery \ ("SELECT * FROM Win32_NTEventLogFile") for log_file in log_files: base = re.sub("event$", "", log_file.FileName) backup_filename = base + u".evt" log_file.BackupEventlog(backup_filename) The following exception is raised File "c:\python25\lib\site-packages\win32com\client\dynamic.py", line 495, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, u'SWbemObjectEx', u'Invalid parameter ', None, 0, -2147217400), None) We traced this problem to WMI issing an unexecpected return code when it is attempted to get a property that is a method. The function __getattr__ in class CDispatch tries to resolve an attribute request as an attribute first, and then, if an error is raisen by COM, as a method: if details[0] in ERRORS_BAD_CONTEXT: # May be a method. self._olerepr_.mapFuncs[attr] = retEntry return self._make_method_(attr) raise pythoncom.com_error, details But the list of such errors seems not be enough. WMI is returning error code winerror.DISP_E_EXCEPTION in this case. We workarounded the problem adding winerror.DISP_E_EXCEPTION to ERRORS_BAD_CONTEXT in dynamic.py, but perhaps there is a more specific solution. Best regards Ramon Garcia ra...@cn... Comisin Nacional de Mercado de Valores ---------------------------------------------------------------------- >Comment By: Roger Upole (rupole) Date: 2008-09-03 17:05 Message: Logged In: YES user_id=771074 Originator: NO I think the underlying problem here is that WMI does not make a distiction between asking for a method and executing it. Both of these produce the error you describe: log_file._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_METHOD, True) log_file._oleobj_.Invoke(id, 0, pythoncom.DISPATCH_PROPERTYGET, True) And both succeed if you pass a filename parameter as an extra arg. This indicates that the error is not produced by attempting to get the attribute, but rather from actually calling the method without a filename parameter. You may want to look at using Tim Golden's WMI module, which provides a much easier to use wrapper for these objects. http://timgolden.me.uk/python/wmi.html ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=2052253&group_id=78018 |