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.

testDCOM.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # testDCOM
  2. usage = """\
  3. testDCOM.py - Simple DCOM test
  4. Usage: testDCOM.py serverName
  5. Attempts to start the Python.Interpreter object on the named machine,
  6. and checks that the object is indeed running remotely.
  7. Requires the named server be configured to run DCOM (using dcomcnfg.exe),
  8. and the Python.Interpreter object installed and registered on that machine.
  9. The Python.Interpreter object must be installed on the local machine,
  10. but no special DCOM configuration should be necessary.
  11. """
  12. import string
  13. import sys
  14. # NOTE: If you configured the object locally using dcomcnfg, you could
  15. # simple use Dispatch rather than DispatchEx.
  16. import pythoncom
  17. import win32api
  18. import win32com.client
  19. def test(serverName):
  20. if string.lower(serverName) == string.lower(win32api.GetComputerName()):
  21. print("You must specify a remote server name, not the local machine!")
  22. return
  23. # Hack to overcome a DCOM limitation. As the Python.Interpreter object
  24. # is probably installed locally as an InProc object, DCOM seems to ignore
  25. # all settings, and use the local object.
  26. clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
  27. ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
  28. ob.Exec("import win32api")
  29. actualName = ob.Eval("win32api.GetComputerName()")
  30. if string.lower(serverName) != string.lower(actualName):
  31. print(
  32. "Error: The object created on server '%s' reported its name as '%s'"
  33. % (serverName, actualName)
  34. )
  35. else:
  36. print("Object created and tested OK on server '%s'" % serverName)
  37. if __name__ == "__main__":
  38. if len(sys.argv) == 2:
  39. test(sys.argv[1])
  40. else:
  41. print(usage)