Dim oIIS, oDir, oFile,a
Dim sName, sPath,sName1, sPath1
sPath = 'Enter the path here
sPath1 = 'Enter the path here for the sub Virtual directory
sName = 'Name of the Virtual directory
sName1 = 'Name of the sub Virtual directory
Set oFile = CreateObject("Scripting.FileSystemObject")
Set a = oFile.CreateTextFile("c:\testfile.txt", True)
a.WriteLine(sPath)
a.WriteLine(sName)
Set oIIS = GetObject("IIS://localhost/W3SVC/1/Root")
On Error Resume Next
Set oDir = oIIS.GetObject("IISWebVirtualDir", sName)
' This will return error -2147024893 if it doesn't exist
a.WriteLine(Err.Number)
if Err.Number = 0 Then oIIS.Delete "IISWebVirtualDir", sName
oIIS.SetInfo
a.WriteLine(Err.Number)
If Err.Number <> 0 Then Set oDir = oIIS.Create("IISWebVirtualDir", sName)
a.WriteLine(Err.Number)
oDir.AuthAnonymous = false
Err.Clear
oDir.AccessScript = True
oDir.Path = sPath
'Create the virtual subdirectory
Set oDir = oIIS.Create("IISWebVirtualDir", sName & "/" & sName1)
oDir.AccessRead = True
oDir.AccessWrite = True
oDir.path = sPath1
oDir.SetInfo
oDir.AppCreate True
oDir.SetInfo
a.Close
' Workaround for bug in II4
oDir.KeyType = "IIsWebVirtualDir"
oDir.SetInfo
oDir.AppCreate True
oDir.SetInfo
Set oDir = Nothing
Set oIIS = Nothing