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

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed May 19 06:38:37 EDT 2004


Y.H. Rhiu
| | 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:

OK, I've got it. What you need is this:

<code>
import wmi

connection = wmi.connect_server (server=".",
namespace="root/MicrosoftIISv2")
c = wmi.WMI (wmi=connection)

#
# Could as well be achieved by doing:
#  web_server = c.IISWebService (Name="W3SVC")[0]
#
for web_server in c.IIsWebService (Name="W3SVC"):
  break
  
binding = c.new ("ServerBinding")
binding.IP = ""
binding.Port = "8383"
binding.Hostname = ""

web_server.CreateNewSite (
  PathOfRootVirtualDir=r"c:\inetpub\wwwroot",
  ServerComment="My Web Site",
  ServerBindings= [binding.ole_object]
)
</code>

The significant thing is that for the ServerBindings
parameter to the CreateNewSite method at the end,
you need (a) to pass in a sequence (albeit of one
entry) and (b) to have the objects in that array
be the ole_object normally delegated to by the 
wmi_object. It's a bit messy, and I'd probably like
to do something a bit more automatic for the future.

But it works.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-win32 mailing list