Programmatic Site Operations

   

Programmatic Site Operations

Using ADSI, you can query the status of a site to verify that it is indeed running. This can be especially handy in cases where you wish to write a service or application to monitor a site, or when you need to cycle the site for Metabase changes to take affect.

Querying Site Status Using Visual Basic

To query a site, simply query the ServerState property for the bound object. The property will return an integer representing the current status of the site, as follows :

Return Code Status
1 Starting
2 Started
3 Stopping
4 Stopped
5 Pausing
6 Paused
7 Continuing

Use the preceding chart and the following Visual Basic code to query the state of an existing IIS site:

 Dim Site As IADs Dim ServerName As String Dim Index As Long ServerName = "IIS_Server_Name" Index = Site_Index_Value Set Site = GetObject("IIS://" & ServerName & "/W3SVC/" & Index) Select Case Site.ServerState     Case 1           Debug.Print "Starting"     Case 2           Debug.Print "Started"     Case 3           Debug.Print "Stopping"     Case 4           Debug.Print "Stopped"     Case 5           Debug.Print "Pausing"     Case 6           Debug.Print "Paused"     Case 7           Debug.Print "Continuing" End Select 

Note

Those familiar with the Windows Load Balancing Service (WLBS) already know that one major weakness in the product is the inability to monitor running services under Windows NT Server 4.0.

When run on Windows NT Server 4.0, WLBS will re-converge the cluster upon heartbeat failure, but cannot detect if a service or site has gone offline .

Using the code in this section, a service can be written that allows you to monitor the entire W3SVC or critical sites and re-converge the cluster if the monitored site is in any state other than starting or started.


Starting a Site Using Visual Basic

After creating a new IIS site and configuring all associated properties, you will likely wish to programmatically start the site. This is easily accomplished by calling the Start method of the appropriate site object.

Consider the following Visual Basic code sample to start the site:

 Dim Site As IADs Dim ServerName As String Dim Index As Long ServerName = "IIS_Server_Name" Index = Site_Index_Value Set Site = GetObject("IIS://" & ServerName & "/W3SVC/" & Index) If Site.ServerState = 4 or Site.ServerState = 3 Then    Site.Start    Debug.Print "Request to start site " & Site.ServerComment & " was issued." End If 

Tip

To start an FTP, SMTP, or NNTP site, simply change the name of the IIS service in the binding string.


Stopping a Site Using Visual Basic

To stop a site, call the Stop method of the bound site object.

Use the following Visual Basic code to bind a specific site and stop publication of the site:

 Dim Site As IADs Dim ServerName As String Dim Index As Long ServerName = "IIS_Server_Name" Index = Site_Index_Value Set Site = GetObject("IIS://" & ServerName & "/W3SVC/" & Index) If Site.ServerState = 2 or Site.ServerState = 1 Then    Site.Stop    Debug.Print "Request to stop site " & Site.ServerComment & " was issued." End If 

Pausing a Site Using Visual Basic

The Pause method of the bound site object allows you to pause operations of the server temporarily. This forces all new connections to the server to be denied . Note that existing connections are not disturbed.

Use the following Visual Basic code to programmatically pause a bound Web server:

 Dim Site As IADs Dim ServerName As String Dim Index As Long ServerName = "IIS_Server_Name" Index = Site_Index_Value Set Site = GetObject("IIS://" & ServerName & "/W3SVC/" & Index) If Site.ServerState = 1 or Site.ServerState = 2 Then    Site.Pause    Debug.Print "Request to pause site " & Site.ServerComment & " was issued." End If 

Continuing a Paused Site Using Visual Basic

To restore a paused server, simply call the Continue method of the bound site object to bring the site back online.

Use the following Visual Basic code to restore a paused site:

 Dim Site As IADs Dim ServerName As String Dim Index As Long ServerName = "IIS_Server_Name" Index = Site_Index_Value Set Site = GetObject("IIS://" & ServerName & "/W3SVC/" & Index) If Site.ServerState = 6 or Site.ServerState = 5 Then    Site.Continue    Debug.Print "Request to continue paused site " & Site.ServerComment & " was issued." End If 

   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net