' Get the name of the current directory
Set fso = WScript.CreateObject( "Scripting.FileSystemObject" )
vDirPath = fso.GetFolder( vDirPath ).Path
' Does this IIS application already exist in the metabase?
On Error Resume Next
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root/" & vDirName )
If Err.Number = 0 Then
result = shell.Popup( "A virtual directory named " & vDirName & " already exists. " & vbCrLf & vbCrLf & "Would you like it re-mapped for this sample?", 0 ,"Remap Virtual Directory?", 4 + 32 )' 4 = YesNo & 32 = Question
If result = 6 Then ' 6 = Yes
DeleteVirtualDirectory vDirName
Else
WScript.Quit
End If
End If
'Using IIS Administration object , turn on script/execute permissions and define the virtual directory as an 'in-process application.
Set objIIS = GetObject( "IIS://localhost/W3SVC/1/Root" )
Set vDirObj = objIIS.Create( "IISWebVirtualDir", vDirName )
If Err.Number > 0 Then
shell.Popup Err.Description, 0, "Error", 16 ' 16 = Stop
WScript.Quit
Else
res = vDirName & " has been created at" & vbCrLf & vDirPath
shell.Popup res, 0, "All done", 64 ' 64 = Information
End If
Sub DeleteVirtualDirectory( NameOfVdir )
Set iis = GetObject("IIS://localhost/W3SVC/1/Root")
iis.Delete "IISWebVirtualDir", vDirName
If Err.Number <> 0 Then
errorString = "Unable to delete exisiting virtual directory."
If Err.Description Is Nothing Then
errorString = errorString & "Error Code: " & Err.Number
Else
errorString = errorString & "Description: " & Err.Description
End If
shell.Popup errorString, 0, "Error", 16 ' 16 = Stop
End If