Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

IIS virtual directory on remote machine


3 replies to this topic

Tomek

Tomek
  • Members
  • 5 posts

Posted 05 March 2001 - 16:22

Is there any possibility to create IIS virtual directory on remote machine ?
Is it possible to access IIS through WMI ?
Could you show me some examples ?

Leigh Ravenhall

Leigh Ravenhall
  • Members
  • 269 posts

Posted 06 March 2001 - 01:39

I haven't tried with WMI, but what you are attempting to do can be done using VBScript.

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.



BobRouse

BobRouse
  • Members
  • 82 posts

Posted 07 August 2001 - 19:15

I've found that creating a VirDir using these commands doesn't actually create the physical directory (unless I'm doing something incorrectly). Here is the function I use (I compile it into an ActiveX DLL and call it, but it should work as VBScript). I have to physically create the dir first:

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