asked on
Domain = "mydomain.com"
FolderName= "\\MySharedStorage\websites\MyDomainFolder"
'This part creates a new folder on the disk
dim filesys, folder, path
path = FolderName
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(path) Then
Set folder = filesys.CreateFolder(path)
End If
Server1 = "192.168.0.1"
'Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer(Server1, "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 = SERVER1
Bindings(0).Port = "80"
Bindings(0).Hostname = Domain
Redim Preserve Bindings(1)
Set Bindings(1) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(1).IP = SERVER1
Bindings(1).Port = "80"
Bindings(1).Hostname = "www." & Domain
' Create the new Web site using the CreateNewSite method of the IIsWebService object.
Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite(Domain, Bindings, FolderName)
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 = "Default 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 " & DOMAIN & " was created with the path and unique site identification number of " & strSitePath