' ********************************************************************* ' ' Name : StopALLCOMPlusApps.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to stop & restart a Com+ application. ' ' Arguments : None. ' ' WIZARD:PARAMS=This script requires no parameters ' WIZARD:PARAMEXAMPLE= ' ' Returns : 0 - Success. ' 1 - An error occurred. ' 2 - One or more warnings issued. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running|2 = One or more warnings were issued.||Script output also indicates "OK" for success, "Warning" or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript). ' ' Change the "TODOs" for your own requirements. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objNetwork ' Network reference Dim objCOMPlus ' COM+ system reference Dim objApplications ' COM+ applications reference Dim objApplication ' COM+ application reference Dim strServer ' Our server name Dim strApplication ' Our app. name Dim intResult ' Overall result ' ------ Main Logic ------ ' Retrieve the server name (assumes local server) Set objNetwork = WScript.CreateObject("WScript.Network") If Err.Number <> 0 Then ' Error WScript.Echo "Error. Unable to create the network object. " & Err.Description WScript.Quit(1) End If strServer = objNetwork.ComputerName ' Connect to COM+ & retrieve apps. Set objCOMPlus = CreateObject("COMAdmin.COMAdminCatalog") If Err.Number <> 0 Then ' Error Set objNetwork = Nothing WScript.Echo "Error. Unable to create the COM+ Admin object. " & Err.Description WScript.Quit(1) End If Set objApplications = objCOMPlus.GetCollection("Applications") If Err.Number <> 0 Then ' Error Set objCOMPlus = Nothing Set objNetwork = Nothing WScript.Echo "Error. Unable to retrieve (link to) the COM+ applications list. " & Err.Description WScript.Quit(1) End If objApplications.Populate If Err.Number <> 0 Then ' Error Set objCOMPlus = Nothing Set objNetwork = Nothing WScript.Echo "Error. Unable to populate the COM+ applications list. " & Err.Description WScript.Quit(1) End If ' Loop round closing each one down intResult = 0 For Each objApplication In objApplications If objApplication.Name <> "System Application" Then ' Close it Call objCOMPlus.ShutdownApplication(objApplication.Name) If Err.Number <> 0 Then ' Warn user Err.Clear WScript.Echo "Warning. Unable to shutdown the COM+ application " & objApplication.Name & ". " & Err.Description intResult = 2 End If End If Next ' Finally close the system app. This must be last Call objCOMPlus.ShutdownApplication("System Application") If Err.Number <> 0 Then ' Warn user Err.Clear WScript.Echo "Warning. Unable to shutdown the COM+ System application. " & Err.Description intResult = 2 Else WScript.Echo "OK. COM+ applications were shutdown successfully" End If ' ------ Cleanup ------ Set objCOMPlus = Nothing Set objApplications = Nothing Set objApplication = Nothing WScript.Quit(intResult) ' ------ End of Script ------