home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Shareware / Comunicatii / jyte / jyte.exe / perfmon.py < prev    next >
Text File  |  1999-09-02  |  1KB  |  28 lines

  1. """A COM Server which exposes the NT Performance monitor in a very rudimentary way
  2.  
  3. Usage from VB:
  4.     set ob = CreateObject("Python.PerfmonQuery")
  5.     freeBytes = ob.Query("Memory", "Available Bytes")
  6. """
  7. from win32com.server import exception, register
  8. import pythoncom, win32pdhutil, winerror
  9.  
  10. class PerfMonQuery:
  11.     _reg_verprogid_ = "Python.PerfmonQuery.1"
  12.     _reg_progid_ = "Python.PerfmonQuery"
  13.     _reg_desc_ = "Python Performance Monitor query object"
  14.     _reg_clsid_ = "{64cef7a0-8ece-11d1-a65a-00aa00125a98}"
  15.     _reg_class_spec_ = "win32com.servers.perfmon.PerfMonQuery"
  16.     _public_methods_ = [ 'Query' ]
  17.     def Query(self, object, counter, instance = None, machine = None):
  18.         try:
  19.             return win32pdhutil.GetPerformanceAttributes(object, counter, instance, machine=machine)
  20.         except win32pdhutil.error, (rc, fn, desc):
  21.             raise exception.Exception(desc=desc)
  22.         except TypeError, desc:
  23.             raise exception.Exception(desc=desc,scode=winerror.DISP_E_TYPEMISMATCH)
  24.                 
  25. if __name__=='__main__':
  26.     print "Registering COM server..."
  27.     register.UseCommandLine(PerfMonQuery)
  28.