On Error Resume Next
Dim ArgObj ' Object which contains the command line argument Dim Result ' Result of the command function call Dim Args(10) ' Array that contains all of the non-global arguments Dim ArgCount ' Tracks the size of the Args array Dim vAppFriendlyName
dim vPath, scriptPath,vName
'Set object to command line arguements Set ArgObj = WScript.Arguments
'Name of virtual web vName = ArgObj(0)
'Path to the files vPath = ArgObj(1)
'appFriendlyName from command line vappFriendlyName = ArgObj(2)
'call to create vDir CAll CreateVDir(vName, vPath, vappFriendlyName)
'code taken from mkwebdir.vbs and changed for single vDir creation. Sub CreateVDir(byVAl vName, byVal vPath, byVal vappFriendlyName)
Dim vRoot,vDir,webSite On Error Resume Next
' get the local host default web or change to the web you want ' replace bigdogsbowling with the name of your website defined inside Internet Svc Manager ' This is case sensative as far as we could tell set webSite = findWeb("localhost", "bigdogsbowling") if IsObject(webSite)=False then Display "Unable to locate the Default Web Site" exit sub else 'display webSite.name end if
' get the root set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root") If (Err <> 0) Then Display "Unable to access root for " & webSite.ADsPath Exit sub else 'display vRoot.name End IF
' delete existing web if needed ' vRoot.Delete "IIsWebVirtualDir",vName ' vRoot.SetInfo Err=0 ' reset error
' create the new web Set vDir = vRoot.Create("IIsWebVirtualDir", vName) If (Err <> 0) Then Display "Unable to create " & vRoot.ADsPath & "/" & vName & "." exit sub else 'display vdir.name end if
' set properties on the new web vDir.AccessRead = true vDir.Accessflags = 513 vDir.Path = vPath vDir.appFriendlyName = vappFriendlyName vDir.appIsolated = 0 VDir.AppCreate False If (Err <> 0) Then Display "Unable to bind path " & vPath & " to " & vRoot.Name & "/" & vName & ". Path may be invalid." exit sub end If
' commit changes vDir.SetInfo If (Err <> 0) Then Display "Unable to save changes for " & vRoot.Name & "/" & vName & "." exit sub end if
' report all ok ' WScript.Echo Now & " " & vName & " virtual directory " & vRoot.Name & "/" & vname & " created successfully." End Sub
Function findWeb(computer, webname) On Error Resume Next
Dim websvc, site dim webinfo Dim aBinding, binding
set websvc = GetObject("IIS://"&computer&"/W3svc") if (Err <> 0) then exit function end if ' First try to open the webname. set site = websvc.GetObject("IIsWebServer", webname) if (Err = 0) and (not isNull(site)) then if (site.class = "IIsWebServer") then ' Here we found a site that is a web server. set findWeb = site exit function end if end if err.clear for each site in websvc if site.class = "IIsWebServer" then ' ' First, check to see if the ServerComment ' matches ' If site.ServerComment = webname Then set findWeb = site exit function End If aBinding=site.ServerBindings if (IsArray(aBinding)) then if aBinding(0) = "" then binding = Null else binding = getBinding(aBinding(0)) end if else if aBinding = "" then binding = Null else binding = getBinding(aBinding) end if end if if IsArray(binding) then if (binding(2) = webname) or (binding(0) = webname) then set findWeb = site exit function End If end if end if next End Function
function getBinding(bindstr)
Dim one, two, ia, ip, hn
one=Instr(bindstr,":") two=Instr((one+1),bindstr,":")
ia=Mid(bindstr,1,(one-1)) ip=Mid(bindstr,(one+1),((two-one)-1)) hn=Mid(bindstr,(two+1))
getBinding=Array(ia,ip,hn) end function
Sub Display(Msg) WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & Msg End Sub
Sub Trace(Msg) WScript.Echo Now & " : " & Msg End Sub
Sub DeleteWeb(WebServer, WebName) ' delete the exsiting web (ignore error if missing) On Error Resume Next Dim vDir display "deleting " & WebName
WebServer.Delete "IISWebVirtualDir",WebName WebServer.SetInfo If Err=0 Then DISPLAY "WEB " & WebName & " deleted." else display "can't find " & webname End If
End Sub |