' Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")
 
' Build binding object, which is a required parameter of the CreateNewSite method.
' Use the SpawnInstance WMI method since we are creating a new instance of an object.
Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = ""
Bindings(0).Port = "8383"
Bindings(0).Hostname = ""
 
' Create the new Web site using the CreateNewSite method of the IIsWebService object.
Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\Inetpub\Wwwroot")
If Err Then
WScript.Echo "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***"
WScript.Quit(1)
End If
 
' strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907'
' To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object.
Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
objPath.Path = strSiteObjPath
strSitePath = objPath.Keys.Item("")
 
' Set some properties on the root virtual directory which was created by CreateNewSite.
Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
vdirObj.EnableDefaultDoc = True
vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
vdirObj.AccessFlags = 513 ' read, script
vdirObj.AppFriendlyName = "Root Application"
 
' Save the new settings to the metabase
vdirObj.Put_()
 
' CreateNewSite does not start the server, so start it now.
Set serverObj = providerObj.Get(strSiteObjPath)
serverObj.Start
 
WScript.Echo "A New site called MyNewSite was created with the path and unique site identification number of " & strSitePath

posted on 2006-05-09 20:05  dahai.net  阅读(475)  评论(0编辑  收藏  举报