Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Iis Create Website
 

Vbscript / Web Servers / Iis Create Website

Function to create a website in Microsoft IIS 6.0 based on a single IIS server IP address using the HTTP host header to identify the website.

Function requires IIS server computer name e.g. 'IISSVR01', Website name e.g. 'mywebsite' and Website directory e.g. 'C:Webrootywebsite'.



Sub createWebsite(strComputer, sitename, webdir)

serverIP = getIP(strComputer)

Set objWMIService = GetObject _
    ("winmgmts:{authenticationLevel=pktPrivacy}" _
        & strComputer & " ootmicrosoftiisv2")

Set objWebService = objWMIService.ExecQuery _
    ("Select * From IISWebService")

arrBindings = Array(0)
Set arrBindings(0) = _
    objWMIService.Get("ServerBinding").SpawnInstance_()
arrBindings(0).IP = serverIP
arrBindings(0).Port = "80"
arrBindings(0).Hostname = sitename

For Each objItem in objWebService
    objItem.CreateNewSite website, arrBindings, webdir
Next

End Sub

Function getIP(strComputer)

strOut = runCMD("ping " & strComputer & " -n 1")
strOut = Right(strOut,Len(strOut)-inStr(strOut,"["))
strOut = Left(strOut,inStr(strOut,"]")-1)

getIP = strOut    

End Function

Function runCMD(strRunCmd)
 
 Set oExec = objShell.Exec(strRunCmd)
 
 strOut = ""

 Do While Not oExec.StdOut.AtEndOfStream
  strOut = strOut & oExec.StdOut.ReadLine()
 Loop

 runCMD = strOut

End Function





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials