PyXR

c:\python24\lib\site-packages\win32 \ com \ test \ testDCOM.py



0001 # testDCOM
0002 usage="""\
0003 testDCOM.py - Simple DCOM test
0004 Usage: testDCOM.py serverName
0005 
0006 Attempts to start the Python.Interpreter object on the named machine,
0007 and checks that the object is indeed running remotely.
0008 
0009 Requires the named server be configured to run DCOM (using dcomcnfg.exe),
0010 and the Python.Interpreter object installed and registered on that machine.
0011 
0012 The Python.Interpreter object must be installed on the local machine,
0013 but no special DCOM configuration should be necessary.
0014 """
0015 # NOTE: If you configured the object locally using dcomcnfg, you could
0016 # simple use Dispatch rather than DispatchEx.
0017 import pythoncom, win32com.client, win32api, string, sys
0018 
0019 def test(serverName):
0020     if string.lower(serverName)==string.lower(win32api.GetComputerName()):
0021         print "You must specify a remote server name, not the local machine!"
0022         return
0023 
0024     # Hack to overcome a DCOM limitation.  As the Python.Interpreter object
0025     # is probably installed locally as an InProc object, DCOM seems to ignore
0026     # all settings, and use the local object.
0027     clsctx = pythoncom.CLSCTX_SERVER & ~pythoncom.CLSCTX_INPROC_SERVER
0028     ob = win32com.client.DispatchEx("Python.Interpreter", serverName, clsctx=clsctx)
0029     ob.Exec("import win32api")
0030     actualName = ob.Eval("win32api.GetComputerName()")
0031     if string.lower(serverName) != string.lower(actualName):
0032         print "Error: The object created on server '%s' reported its name as '%s'" % (serverName, actualName)
0033     else:
0034         print "Object created and tested OK on server '%s'" % serverName
0035 
0036 if __name__=='__main__':
0037     if len(sys.argv) == 2:
0038         test(sys.argv[1])
0039     else:
0040         print usage
0041 

Generated by PyXR 0.9.4
SourceForge.net Logo