home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32com_test_testDCOM.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  1.6 KB  |  41 lines

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