Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

perfmon.py 1.1KB

1 year ago
12345678910111213141516171819202122232425262728293031323334
  1. """A COM Server which exposes the NT Performance monitor in a very rudimentary way
  2. Usage from VB:
  3. set ob = CreateObject("Python.PerfmonQuery")
  4. freeBytes = ob.Query("Memory", "Available Bytes")
  5. """
  6. import pythoncom
  7. import win32pdhutil
  8. import winerror
  9. from win32com.server import exception, register
  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(
  20. object, counter, instance, machine=machine
  21. )
  22. except win32pdhutil.error as exc:
  23. raise exception.Exception(desc=exc.strerror)
  24. except TypeError as desc:
  25. raise exception.Exception(desc=desc, scode=winerror.DISP_E_TYPEMISMATCH)
  26. if __name__ == "__main__":
  27. print("Registering COM server...")
  28. register.UseCommandLine(PerfMonQuery)