VirtualDirectory.Create Method1

Creates a virtual directory.

Syntax

objAppSrv.Get("VirtualDirectory").Create(  
   VirtualDirectoryPath,  
   ApplicationPath,  
   PhysicalPath,  
   SiteName  
);  
  
objAppSrv.Get("VirtualDirectory").Create(  
   VirtualDirectoryPath,  
   ApplicationPath,  
   PhysicalPath,  
   SiteName  
)  

Parameters

Name Description
VirtualDirectoryPath A string value that contains the virtual directory path (for example, "/MyVDir").
ApplicationPath A string value that contains the application path (for example, "/MyApp").
PhysicalPath An optional string value that contains the physical path to the file directory where the content for the virtual directory is stored (for example, "C:\inetpub\MyVDirFiles"). Although this parameter is optional, most implementations will require it. Note: IIS does not check for the existence of the specified physical directory. If you specify an invalid path and attempt to open the virtual directory in IIS Manager, IIS Manager will display the error message "Could not find a part of the path '<path>'".
SiteName A string value that contains the name of the Web site for the virtual directory (for example, "Default Web Site").

Return Value

This method does not return a value.

Remarks

The VirtualDirectory object inherits from the ConfiguredObject class; it does not inherit from the VirtualDirectoryElementDefaults class. This means that the properties on the VirtualDirectoryElementDefaults object must also be declared on the VirtualDirectory object.

Example

The following example creates a virtual directory called MyVDir under the MyApp application on the default Web site.

' Connect to the WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Define the parameters.  
strVDirPath = "/MyVDir"  
strAppPath = "/MyApp"  
strPhysicalPath = "C:\inetpub\MyVDirFiles"  
strSiteName = "Default Web Site"  
  
' Create the new virtual directory.  
oWebAdmin.Get("VirtualDirectory").Create _  
    strVDirPath, strAppPath, strPhysicalPath, strSiteName  

Requirements

Type Description
Client - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- IIS 7.5 on Windows Server 2008 R2
- IIS 8.0 on Windows Server 2012
- IIS 8.5 on Windows Server 2012 R2
- IIS 10.0 on Windows Server 2016
Product - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF file WebAdministration.mof

See Also

VirtualDirectory Class
VirtualDirectoryContainsConfigurationSection Class