' ********************************************************************* ' ' Name : RestartCOMPlusApp.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. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript). ' ' Change the "TODOs" for your own requirements. ' ' WIZARD:REMOTE ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objNetwork ' Network reference Dim objCOMPlus ' COM+ system reference Dim strServer ' Our server name Dim strApplication ' Our app. name ' ------ Main Logic ------ ' TODO: Set the COM+ app. name strApplication = "Your COM+ Application Name" ' 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+ 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 objCOMPlus.Connect(strServer) If Err.Number <> 0 Then ' Error Set objCOMPlus = Nothing Set objNetwork = Nothing WScript.Echo "Error. Unable to connect to COM+ on the server " & strServer & ". " & Err.Description WScript.Quit(1) Else ' Attempt to shutdown the app objCOMPlus.ShutdownApplication(strApplication) If Err.Number <> 0 Then ' Error Set objCOMPlus = Nothing Set objNetwork = Nothing WScript.Echo "Error. Unable to shut down the COM+ application " & strApplication & ". " & Err.Description WScript.Quit(1) End If ' Now attempt to restart it objCOMPlus.StartApplication(strApplication) If Err.Number <> 0 Then ' Error Set objCOMPlus = Nothing Set objNetwork = Nothing WScript.Echo "Error. Unable to restart the COM+ application " & strApplication & ". " & Err.Description WScript.Quit(1) End If End If ' ------ Cleanup ------ Set oCatalog = Nothing Set objNetworkSet = Nothing WScript.Echo "OK. COM+ application restarted successfully" WScript.Quit(0) ' ------ End of Script ------