Deleting a Cluster Resource

Deleting a Cluster Resource

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following example deletes a cluster resource.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: deleteClusterResource()
' Purpose:  Deletes a cluster resource.
'
' Input:    szClusterName:            Name of cluster server to query
'           szGroupName:              Name of cluster group
'           szHTTPInstanceName:       Name of HTTP cluster resource being delete
'           szUserName:               Admin username
'           szPassword:               Admin Password
'
' Output:   deleteClusterResource:    Contains Error code (if any)
'
' Note:  In order for this example to function correctly, it may be necessary to include
' references to the following libraries: Active DS Type Library, Microsoft CDO for
' Exchange Management Library, Microsoft Cluster Service Automation Classes,
' Microsoft CDO for Windows 2000 Library.
'//////////////////////////////////////////////////////////////////////
Public Function deleteClusterResource(szClusterName As String, _
                                      szGroupName As String, _
                                      szHTTPInstanceName As String, _
                                      szUserName As String, _
                                      szPassword As String) As Integer

    ' Setup error handler.
    On Error GoTo errhandler

    ' Declare objects.
    Dim oCluster As New msclusterlib.Cluster
    Dim oGroup As msclusterlib.ClusResGroup
    Dim oResources As msclusterlib.ClusResGroupResources
    Dim szClusterGroupName As String
    Dim iGroupCount As Integer
    Dim iResourceCount As Integer
    Dim iIndex As Integer

    szClusterGroupName = ""

    oCluster.Open szClusterName

    ' Get the name of the group that the specified server belongs to.
    For iGroupCount = 1 To oCluster.ResourceGroups.Count
        For iResourceCount = 1 To oCluster.ResourceGroups(iGroupCount).Resources.Count
            If oCluster.ResourceGroups(iGroupCount).Resources(iResourceCount).TypeName = "Network Name" Then
                If UCase(oCluster.ResourceGroups(iGroupCount).Resources(iResourceCount).PrivateProperties(1).value) = UCase(szGroupName) Then
                    szClusterGroupName = oCluster.ResourceGroups(iGroupCount).Name
                    Exit For
                End If
            End If
        Next
        If szClusterGroupName <> "" Then
            Exit For
        End If
    Next

    Set oGroup = oCluster.ResourceGroups.Item(szClusterGroupName)
    Set oResources = oGroup.Resources

    ' Find the resource in the cluster that corresponds to this HTTP virtual server instance.
    For iIndex = 1 To oResources.Count
        If UCase(oResources(iIndex).Name) = UCase(szHTTPInstanceName + cszHTTPClusterSuffix) Then

            'Delete the resource and exit the for loop.
            oResources.DeleteItem (iIndex)
            Exit For
        End If
    Next

    ' Clean up.
    Set oCluster = Nothing
    Set oGroup = Nothing
    Set oResources = Nothing

    Exit Function

    ' Error handling.
errhandler:

    Set oCluster = Nothing
    Set oGroup = Nothing
    Set oResources = Nothing
    ' Implement error logging here.

End Function

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.