以程式控制將遠端機器上的 COM+ 應用程式 shutdown VBScript 範例: '************************************************************************************* dim sMachineName dim sAppName sMachineName = InputBox("Name of W2K computer you would like to stop a COM+ package on...", "Computer Name?") sAppName = InputBox ("Name of COM+ Application to shut down...","Application Name?") If (Len(sMachineName) > 0) And (Len(sAppName) > 0) Then Call ShutDownCOMApplication (sMachineName, sAppName) End If Sub ShutDownCOMApplication(vsMachineName, vsApplicationName) On Error Resume Next Dim objCatalog 'As COMAdminCatalog Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog") Call objCatalog.Connect(vsMachineName) 'Replace with any Windows 2000 computer name 'Shutdown the application Call objCatalog.ShutdownApplication(vsApplicationName) If (Err) Then wscript.Echo "Error shutting down Application " & sAppName & " on " & sMachineName Else wscript.Echo "Application " & sAppName & " shut down on " & sMachineName End If Set objCatalog = Nothing End Sub '************************************************************************************* Delphi 6 範例: Uses ComAdmin, OleServer, CmAdmCtl; // 使用 Delphi 6 的 TCOMAdminCatalog 元件 procedure TForm1.Button1Click(Sender: TObject); begin COMAdminCatalog1.ICOMAdminCatalog_Connect('137.33.4.240'); COMAdminCatalog1.ShutdownApplication(應用程式名稱); end; // 使用 ICOMAdminCatalog procedure TForm1.Button2Click(Sender: TObject); var intfComAdmin: ICOMAdminCatalog; begin intfComAdmin := CoCOMAdminCatalog.Create; intfComAdmin.Connect('137.33.4.240'); intfComAdmin.ShutdownApplication(應用程式名稱); end; 註:Delphi 6 的 RemoteMachineName 是給 DCOM 存取用的,不能用來連 接遠端的 COMAdminCatalog 伺服器。