win32com - Code snippet works in VBScript but not Python.

Gurdon Merchant, Jr. Gurdon_Merchant at ml.com
Mon Mar 11 09:22:48 EST 2002


The Python win32com package works fine for most COM work.  However,
I'm having problems with cases where the reference is to be used to
invoke a method which creates another object.

Here is a VBScript snippet that works fine:

' START VBSCRIPT SNIPPET
' vbtest.vbs
Dim WshController
Set WshController = WScript.CreateObject("WshController")

Dim localVbscriptToRun
localVbscriptToRun = "c:\temp\test-script.vbs"

Dim remotePc
remotePc = WScript.Arguments(0)

Dim RemoteScript
Set RemoteScript = WshController.CreateScript(localVbscriptToRun,
remotePc)

' END VBSCRIPT SNIPPET

But the equivalent Python code:

# START PYTHON SNIPPET
# pytest.py

import sys
import win32com.client
WshController = win32com.client.Dispatch("WshController")

localVbscriptToRun = "c:\\temp\\test-script.vbs"

remotePc = sys.argv[1]

RemoteScript = WshController.CreateScript(localVbscriptToRun,
remotePc)

# END PYTHON SNIPPET

fails with this exception:

Traceback (most recent call last):
  File "C:\temp\pytest.py", line 10, in ?
    RemoteScript = WshController.CreateScript(localVbscriptToRun,
remotePc)
  File "<COMObject WshController>", line 2, in CreateScript
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None,
None, None, 0, -2147024891), None)

To make the following code snippets run you must:
  1) Be on NT4 Sp6 or higher.
  2) ActiveState Python 2.1.212 (or Python with win32all).
  3 "Remote" = "1" (type REG_SZ) in:
     "HKLM\Software\Microsoft\Windows Script Host\Settings"
     on both local and remote PC (WshController requirement).
  4) Have Scripting engines 5.6 or higher installed.
  5) Have a c:\temp\test-script.vbs with at least a blank
     line.
  6) Invoke the code snippets with UNC (\\foo) format
     of name of a remote PC you have local administrator
     privs on (or use name of local PC).

The VBScript will execute correctly.  The Python code will not. 
win32com works for me in other examples.  I just seem to be having
problems in cases where I try to invoke a method on a returned object.
 That is, lines similar to "RemoteScript =
WshController.CreateScript(localVbscriptToRun)".

I appear to be missing some subtle point.  Can anyone shed some light
on it?


Thanks in advance,

Gurdon Merchant, Jr.
Gurdon_Merchant at ml.com



More information about the Python-list mailing list