Skip to content

Instantly share code, notes, and snippets.

@segilbert
Created January 20, 2012 21:15
Show Gist options
  • Save segilbert/1649661 to your computer and use it in GitHub Desktop.
Save segilbert/1649661 to your computer and use it in GitHub Desktop.
Remove COM+ Applications Pro-grammatically from COM+ Services
On Error Resume Next
For Each objItem in colItems
' Create an instance of COMAdmin Catalog
set cat = CreateObject( "COMAdmin.COMAdminCatalog" )
' Reference the Applications Collection
Set apps = cat.GetCollection("Applications")
' Retrieve the data
apps.Populate
Dim appName1, appName2
appName1 = "NameOfComPlusApplication_ONE_ToRemove"
appName2 = "NameOfComPlusApplication_TWO_ToRemove"
Dim changesToDeletable, changesApplications
changesToDeletable = false
changesApplications = false
' Fisrt set the deletable attribute
For i = 0 to apps.Count
' query application collection x for name and compare
If ( apps.Item(i).Name = appName1 Or apps.Item(i).Name = appName2 ) Then
' we have a match, nuke it
' Wscript.echo( " Deleteable - " & apps.Item(i).Value("Deleteable") )
If ( apps.Item(i).Value("Deleteable") = false ) Then
Wscript.echo("Found COM+ Application Name - " & apps.Item(i).Name & "Index - " & i & " Now make it deletable")
apps.Item(i).Value("Deleteable") = true
Wscript.echo("COM+ Application Name - " & apps.Item(i).Name & "Index - " & i & " is not deleteable")
changesToDeletable = true
End If
End If
Next
If ( changesToDeletable ) Then
'commit changes
Wscript.echo(" Start Saving Changes for removals in COM+ Services." )
apps.SaveChanges()
Wscript.echo(" Save COMPLETE Changes for removals in COM+ Services." )
Else
Wscript.echo(" There are no COM+ applications with name - " & appName1 & " or " & appName2 & " that require a update to Deletable property." )
End If
' Reference the Applications Collection
Set apps = cat.GetCollection("Applications")
' Retrieve the data
apps.Populate
' Loop from upperbound to lower since the Remove method
' triggers an automatic reindexing.
' http://msdn.microsoft.com/en-us/library/ms684329(v=vs.85).aspx
For i = apps.Count - 1 to 0 step -1
' query application collection x for name and compare
If ( apps.Item(i).Name = appName1 Or apps.Item(i).Name = appName2 ) Then
' we have a match, nuke it
Wscript.echo("**********************")
Wscript.echo("Found COM+ Application Name - " & apps.Item(i).Name & "Index - " & i)
Wscript.echo(apps.Item(i).Name & "Index - " & i & " has Deletable property set to - " & apps.Item(i).Value("Deleteable"))
If ( apps.Item(i).Value("Deleteable") ) Then
apps.Remove (i)
Wscript.echo("Removed COM+ Application Name - " & apps.Item(i).Name & "Index - " & i)
Else
Wscript.echo("COM+ Application Name - " & apps.Item(i).Name & "Index - " & i & " will NOT be removed it is on Deletable.")
End If
Wscript.echo("**********************")
changesApplications = true
End If
Next
If ( changesApplications ) Then
'commit changes
Wscript.echo("**********************")
Wscript.echo(" Start Saving Changes for removals in COM+ Services." )
apps.SaveChanges()
Wscript.echo(" Sav COMPLETE Changes for removals in COM+ Services." )
Wscript.echo("**********************")
Else
Wscript.echo(" There are no COM+ applications with name - " & appName1 & " or " & appName2 & " that have been deleted." )
End If
'' Verify Changes
For i = 0 to apps.Count
' query application collection x for name and compare
If ( apps.Item(i).Name = appName1 Or apps.Item(i).Name = appName2 ) Then
' we have a match, nuke it
Wscript.echo("**********************")
Wscript.echo("Found COM+ Application Name - " & apps.Item(i).Name & "Index - " & i)
Wscript.echo(apps.Item(i).Name & "Index - " & i & " has Deletable property set to - " & apps.Item(i).Value("Deleteable"))
Wscript.echo("**********************")
End If
Next
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment