[python-win32] Converting VBScript using WMI to Python: data type problem

Y.H. Rhiu master at hilug.org
Wed May 19 03:36:59 EDT 2004


Hi, I'd like to write a python script that create IIS site and virtual
directories, using WMI.
But I have a problem with converting sample VBScript code to Python code:

<code=VBScript>
' Source:
http://www.microsoft.com/resources/documentation/windowsserv/2003/datacenter/proddocs/en-us/prog_wmi_tut_03_03.asp?frame=true
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer("MyMachine",
"root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")

Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = ""
Bindings(0).Port = "8383"
Bindings(0).Hostname = ""

Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings,
"C:\Inetpub\Wwwroot")
</code>

<code=Python>
from win32com.client import *

locatorObj = Dispatch("WbemScripting.SWbemLocator")
providerObj = locatorObj.ConnectServer(".", "root/MicrosoftIISv2")
serviceObj = providerObj.Get("IIsWebService='W3SVC'")
Bindings = providerObj.Get("ServerBinding").SpawnInstance_()

Bindings.Properties_('Hostname').Value = 'mydomain.com'
Bindings.Properties_('IP').Value = ''
Bindings.Properties_('Port').Value = '80'

InParam = serviceObj.Methods_('CreateNewSite').InParameters.SpawnInstance_()
InParam.Properties_('PathOfRootVirtualDir').Value = 'c:\\inetpub\\wwwroot'
InParam.Properties_('ServerComment').Value = 'my web site'
InParam.Properties_('ServerBindings').Value = Bindings  # ERROR occurs here

strSiteObjPath = serviceObj.ExecMethod_('CreateNewSite',InParam)
</code>

I think the problem is a conflict of data type on 15th line in above code.
Can I have a solution of workaround for this?
Any guidance will be appreciated.

__
Y.H. Rhiu





More information about the Python-win32 mailing list