AssemblyInstaller.Commit(IDictionary) 方法

定義

完成安裝異動。Completes the installation transaction.

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,包含安裝程式集合中的所有安裝程式都執行過之後的電腦狀態。An IDictionary that contains the state of the computer after all the installers in the installer collection have run.

例外狀況

savedState 參數為 nullThe savedState parameter is null.

-或--or- IDictionary 的儲存狀態可能已經損毀。The saved-state IDictionary might have been corrupted.

-或--or- 無法找到檔案。A file could not be found.

在集合中有一個安裝程式的 Committing 事件處理常式發生錯誤。An error occurred in the Committing event handler of one of the installers in the collection.

-或--or- 在集合中有一個安裝程式的 Committed 事件處理常式發生錯誤。An error occurred in the Committed event handler of one of the installers in the collection.

-或--or- 在安裝的 Commit(IDictionary) 階段時發生例外狀況。An exception occurred during the Commit(IDictionary) phase of the installation. 例外狀況會被忽略,安裝會繼續進行。The exception is ignored and the installation continues. 不過,安裝完成之後,應用程式可能無法正常運作。However, the application might not function correctly after installation completes.

-或--or- 在其中一個組件中無法找到安裝程式型別。Installer types were not found in one of the assemblies.

-或--or- 無法建立其中一個安裝程式型別的執行個體。An instance of one of the installer types could not be created.

在安裝的 Commit(IDictionary) 階段時發生例外狀況。An exception occurred during the Commit(IDictionary) phase of the installation. 例外狀況會被忽略,安裝會繼續進行。The exception is ignored and the installation continues. 不過,安裝完成之後,應用程式可能無法正常運作。However, the application might not function correctly after installation completes.

範例

下列範例示範的是AssemblyInstaller方法, Install以及AssemblyInstaller類別Commit的和方法。The following example demonstrates the AssemblyInstaller constructor and the Install and Commit methods of the AssemblyInstaller class.

類別AssemblyInstaller是藉由叫用此AssemblyInstaller函式來建立。An AssemblyInstaller class is created by invoking the AssemblyInstaller constructor. 已設定這個物件的屬性,並Install呼叫和Commit方法來安裝MyAssembly_Install.exe元件。The properties of this object are set and the Install and Commit methods are called to install the MyAssembly_Install.exe assembly.

#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實例中所有安裝程式的方法都成功時,才會呼叫這個方法。This method is called only if the Install methods of all the installers in this instance's InstallerCollection succeed. 然後,這個方法會Commit呼叫集合中每個安裝程式的方法。This method then calls the Commit method of each installer in the collection.

儲存您可能需要的任何資訊,以在儲存狀態IDictionary下執行正確的卸載作業,而此作業會傳遞Uninstall至方法。Store any information that you might need to do a correct uninstall operation in the saved-state IDictionary, which is passed to the Uninstall method.

適用於