語言

AssemblyInstaller.Commit(IDictionary) 方法

定義

完成安裝交易。

public:
 override void Commit(System::Collections::IDictionary ^ savedState);
public override void Commit(System.Collections.IDictionary savedState);
override this.Commit : System.Collections.IDictionary -> unit
Public Overrides Sub Commit (savedState As IDictionary)

參數

savedState
IDictionary

一個 IDictionary 包含安裝程式集合中所有安裝程式執行後電腦狀態的

例外狀況

參數 savedState 為 null。

-或-

被拯救的國家 IDictionary 可能已經腐化。

-或-

找不到檔案。

集合中其中一個安裝程式的事件處理程式發生 Committing 錯誤。

-或-

集合中其中一個安裝程式的事件處理程式發生 Committed 錯誤。

-或-

在安裝階段 Commit(IDictionary) 發生了例外。 例外被忽略,安裝繼續進行。 然而,安裝完成後,應用程式可能無法正常運作。

-或-

安裝器類型在其中一個組件中未被發現。

-或-

無法建立其中一種安裝程式類型的實例。

在安裝階段 Commit(IDictionary) 發生了例外。 例外被忽略,安裝繼續進行。 然而,安裝完成後,應用程式可能無法正常運作。

範例

以下範例展示AssemblyInstaller該Install類別的建構子與CommitAssemblyInstaller方法。

AssemblyInstaller類別是透過呼叫AssemblyInstaller建構子來建立的。 設定此物件的屬性,並 Install 呼叫 and Commit 方法來安裝組裝套件 MyAssembly_Install.exe 。

#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
   IDictionary^ mySavedState = gcnew Hashtable;
   Console::WriteLine( "" );
   try
   {
      // Set the commandline argument array for 'logfile'.
      array<String^>^myString = {"/logFile=example.log"};
      
      // Create an Object* of the 'AssemblyInstaller' class.
      AssemblyInstaller^ myAssemblyInstaller = gcnew AssemblyInstaller;

      // Set the properties to install the required assembly.
      myAssemblyInstaller->Path = "MyAssembly_Install.exe";
      myAssemblyInstaller->CommandLine = myString;
      myAssemblyInstaller->UseNewContext = true;
      
      // Clear the 'IDictionary' Object*.
      mySavedState->Clear();
      
      // Install the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Install( mySavedState );
      
      // Commit the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Commit( mySavedState );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
   }
}
using System;
using System.Configuration.Install;
using System.Collections;
using System.Collections.Specialized;

class MyInstallClass
{
   static void Main()
   {
      IDictionary mySavedState = new Hashtable();

      Console.WriteLine( "" );

      try
      {
         // Set the commandline argument array for 'logfile'.
         string[] myString = new string[ 1 ];
         myString[ 0 ] = "/logFile=example.log";

         // Create an object of the 'AssemblyInstaller' class.
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();

         // Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe";
         myAssemblyInstaller.CommandLine = myString;
         myAssemblyInstaller.UseNewContext = true;

         // Clear the 'IDictionary' object.
         mySavedState.Clear();

         // Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install( mySavedState );

         // Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit( mySavedState );
      }
      catch( Exception )
      {
      }
   }
}
Imports System.Configuration.Install
Imports System.Collections
Imports System.Collections.Specialized

Class MyInstallClass
   
   Shared Sub Main()
      Dim mySavedState = New Hashtable()
      
      Console.WriteLine("")
      

      Try
         ' Set the commandline argument array for 'logfile'.
         Dim myString(0) As String
         myString(0) = "/logFile=example.log"
         ' Create an object of the 'AssemblyInstaller' class.
         Dim myAssemblyInstaller As New AssemblyInstaller()
         ' Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe"
         myAssemblyInstaller.CommandLine = myString
         myAssemblyInstaller.UseNewContext = True
         
         ' Clear the 'IDictionary' object.
         mySavedState.Clear()
         
         ' Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install(mySavedState)
         
         ' Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit(mySavedState)
      Catch
      End Try

   End Sub
End Class

備註

此方法僅在所有安裝程式的方法皆 Install 成功 InstallerCollection 時才被呼叫。 此方法接著呼叫 Commit 集合中每個安裝程式的方法。

將你可能需要的正確卸載操作資訊儲存在儲存狀態 IDictionary中,該狀態會傳遞給 Uninstall 方法。

適用於