Freigeben über


Creating Sites and Virtual Directories Using ADSI

Creating sites and virtual directories is one of the most common tasks of an administrator. In IIS 6.0, a new method called CreateNewSite was provided in both the IIS ADSI provider and the IIS WMI provider. The example in this topic works for any version of IIS after IIS 4.0. For an example using CreateNewSite, see IisWebService.CreateNewSite.

The following example code shows you how to use the VBScript programming language to create a Web virtual directory and create an application on the virtual directory.

This example requires IIS 5.0, IIS 5.1, or IIS 6.0 running in IIS 5.0 isolation mode.

' Create an instance of the virtual directory object  
' that represents the default Web site. 
Set IIsWebVDirRootObj = GetObject("IIS://localhost/W3SVC/1/Root") 

' Use the Windows ADSI container object "Create" method to create  
' a new virtual directory. 
Set IIsWebVDirObj = IIsWebVDirRootObj.Create("IIsWebVirtualDir", "NewVDir") 

' Use the Windows ADSI object "Put" method to  
' set some required properties. 
IIsWebVDirObj.Put "Path", "C:\NewContent"  
IIsWebVDirObj.Put "AccessRead", True 
IIsWebVDirObj.Put "AccessScript", True 

' Use the AppCreate2 method of the IIS ADSI provider to  
' create an application on the new virtual directory. 
IIsWebVDirObj.AppCreate2 1 
IIsWebVDirObj.Put "AppFriendlyName", "NewApp" 

' Use the Windows ADSI object "SetInfo" method to  
' save the data to the metabase. 
IIsWebVDirObj.SetInfo