IIS virtual directory on remote machine
Posted 05 March 2001 - 16:22
Is it possible to access IIS through WMI ?
Could you show me some examples ?
Posted 06 March 2001 - 01:39
Get the IIS root object, then create the virtual directory, set the properties and you're done. I know that was way too brief, so if you need more information, try this link.
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/iisref/aore94th.htm
If required, let me know and I can send you my poorly written script.
Posted 07 August 2001 - 19:15
Public Function CreateVirDir(ByVal strDir As String, ByVal strPath As String, ByVal bDisableAnonLogin As Boolean) As Boolean
On Error GoTo ErrHandler
Dim objIIS As Object
Dim objDir As Object
Dim strSubDir As String
Dim strVirPath As String
strSubDir = Trim$(strDir)
strVirPath = Trim$(strPath)
' Initialize connection to IIS
Set objIIS = CreateObject("IIS://localhost/W3SVC/1/Root")
' --- Get the virtual dir object, create it if it doesn't exist. ---
On Error Resume Next ' This is because the next line WILL error if dir does not exist
' This will return error -2147024893 if it doesn't exist
Set objDir = objIIS.GetObject("IIsWebVirtualDir", strSubDir)
' if errored, then create
If Err.Number = -2147024893 Then
On Error GoTo ErrHandler
Set objDir = objIIS.Create("IIsWebVirtualDir", strSubDir)
Else
On Error GoTo ErrHandler
End If
objDir.AccessScript = True
objDir.Path = strVirPath
' Workaround for bug in II4
objDir.KeyType = "IIsWebVirtualDir"
objDir.SetInfo
' if disabling anonymous login...
If bDisableAnonLogin Then
objDir.Authanonymous = False
objDir.SetInfo
objDir.AuthNTLM = True
objDir.SetInfo
End If
CreateVirDir = True
CloseUp:
Set objIIS = Nothing
Set objDir = Nothing
Exit Function
ErrHandler:
strErrMsg = Err.Description
CreateVirDir = False
GoTo CloseUp
' for testing purposes only
Resume
End Function