共用方式為


IIsWebService.CreateNewSite (WMI)

The CreateNewSite method creates a new Web or FTP site. This method allows you to specify the site identification number that you want to use. If you do not specify a site identification number, the method performs a hash function on the ServerComment passed to the method and creates a new number.

Note

This method is only available on IIS 6.0 and later.

strPath = objIIsWebService.CreateNewSite(
      ServerComment,
      ServerBindings[],
      PathOfRootVirtualDir,
      ServerId
)

Parameters

  • ServerComment
    [in] String containing the ServerComment for the new Web site. In IIS Manager, this would be the Description field under Web Site Identification in a Web Site property sheet.

  • ServerBindings[]
    [in] An array of ServerBinding (WMI) objects specifying what server bindings you want on this site. Each server binding includes at least one of the host name, port, or IP address.

  • PathOfRootVirtualDir
    [in] String containing a fully qualified path to a physical directory to which you want the Web site mapped.

  • ServerId
    [in, optional] Long integer containing the site identification number which you want the method to use. If this parameter is empty, a hash function is used to create the site identification number.

Return Values

Returns a string containing the metabase path to the new FTP site.

If a site already exists with the ServerComment that you want to use, an error is not returned because the new site can still be created with a unique site identification number.

Remarks

In the IIS metabase, sites are represented by the service type, and a unique site identification number. For example, on a new installation of IIS, the default Web site is represented in ADSI as w3svc/1.

In IIS versions 5.1 and earlier, the site identification number increases by one for each new site created. For example, if you create a Web site whose path is w3svc/3, the next site you create will become w3svc/4.

CreateNewSite allows you to specify the site identification number that you want to use. If you do not specify a site identification number, the method performs a hash function on the ServerComment passed to the method and creates a new number. If there are multiple sites with the same ServerComment, the hash function detects a collision and selects the next available site identification number. For example, create a site with the following line of code:

myNewSiteID = oIIsWebServiceObj.CreateNewSite("MyNewSite", Bindings, "C:\Inetpub\Wwwroot")

If there is already a Web site on the server called MyNewSite whose site identification number is 5555, then CreateNewSite will return 5556 if 5556 is not already taken.

If you create duplicate sites on multiple IIS 6.0 servers using the IIS Manager or the CreateNewSite method, there is a good chance that the site identification numbers will be the same on each server for each duplicated site. These servers can then be included in a Microsoft Application Center Web farm without problems.

Example Code

' Make connections to WMI, to the IIS namespace on MyMachine, and to the WWW service. 
set locatorObj = CreateObject("Wbemscripting.SWbemLocator") 
set providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2") 
set serviceObj = providerObj.Get("IIsWebService='W3SVC'") 

' Build binding object, which is a required parameter of the CreateNewSite method. 
' Use the SpawnInstance WMI method since we are creating a new instance of an object. 
Bindings = Array(0) 
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_() 
Bindings(0).IP = "" 
Bindings(0).Port = "8383" 
Bindings(0).Hostname = "" 

' Create the new Web site using the CreateNewSite method of the IIsWebService object. 
Dim strSiteObjPath 
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\Inetpub\Wwwroot") 

A more complete example is in the Module Three, Lesson 3 of the IIS WMI Provider Tutorial.

Requirements

Server: Requires or Windows Server 2003.

Product: IIS

See Also

Concepts

IIsWebService (WMI)

Using WMI to Configure IIS

WebSvcExtRestrictionList

ApplicationDependencies

Adding Web Service Extensions to the Restriction List

Installing and Uninstalling CGI and ISAPI Extensions