InstallContextとは? わかりやすく解説

InstallContext クラス

現在のインストールに関する情報格納します

名前空間: System.Configuration.Install
アセンブリ: System.Configuration.Install (system.configuration.install.dll 内)
構文構文

Public Class InstallContext
Dim instance As InstallContext
public class InstallContext
public ref class InstallContext
public class InstallContext
public class InstallContext
解説解説

通常InstallContext は、アセンブリインストールする InstallUtil.exe などのインストール実行可能ファイルによって作成されます。セットアップ プログラム (インストール実行可能ファイル) は、既定ログ ファイル パスコマンド ライン パラメータ渡して InstallContext コンストラクタ呼び出します。

セットアップ プログラムは、InstallCommitRollback、または Uninstall の各メソッド呼び出す前にInstallerContext プロパティとして InstallContextインスタンス設定します。これらのメソッド呼び出す前に、Installers プロパティインストーラ コレクション格納している Installer が、それぞれ格納している各インストーラContext プロパティ設定します

Parameters プロパティは、インストール実行可能ファイル実行時入力されコマンド ライン解析した結果格納します。このプロパティには、ログ ファイルへのパスコンソールログ情報表示するかどうかインストール中にユーザー インターフェイス表示するかどうかなどの情報格納されます。コマンド ライン パラメータtrue かどうか確認するには、IsParameterTrue メソッド呼び出します。

ステータス メッセージインストール ログ ファイルコンソール書き込むには、LogMessage メソッド使用します

使用例使用例

InstallContext クラスの InstallContext コンストラクタParameters プロパティ、および LogMessageIsParameterTrue の各メソッドの例を次に示します

インストーラInstall メソッド呼び出されると、コマンド ラインパラメータチェックされます。それに応じて進行状況メッセージコンソール表示し指定したログ ファイルにも保存します

引数なしでプログラム起動すると、空の InstallContext作成されます。"/LogFile" および "/LogtoConsole" を指定した場合それぞれの引数InstallContext渡してInstallContext作成されます。

Imports System
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Collections
Imports System.Collections.Specialized

Namespace MyInstallContextNamespace
   <RunInstallerAttribute(True)> Class
 InstallContext_Example
      Inherits Installer
      Public myInstallContext As InstallContext

      Public Overrides Sub
 Install(mySavedState As IDictionary)
         Dim myStringDictionary As StringDictionary
 = myInstallContext.Parameters
         If myStringDictionary.Count = 0 Then
            Console.WriteLine("No parameters have been entered
 in the command line" + _
                        "hence, the install will take place in
 the silent mode")
         Else
            ' Check wether the "LogtoConsole" parameter has
 been set.
            If myInstallContext.IsParameterTrue("LogtoConsole")
 = True Then
               ' Display the message to the console and add it to the
 logfile.
               myInstallContext.LogMessage("The 'Install' method
 has been called")
            End If
         End If
         ' The 'Install procedure should be added here.
      End Sub 'Install

      Public Overrides Sub
 Uninstall(mySavedState As IDictionary)
         ' The 'Uninstall' procedure should be added here.
      End Sub 'Uninstall

      Public Overrides Sub
 Rollback(mySavedState As IDictionary)
         If myInstallContext.IsParameterTrue("LogtoConsole")
 = True Then
            myInstallContext.LogMessage("The 'Rollback' method
 has been called")
         End If
         ' The 'Rollback' procedure should be added here.
      End Sub 'Rollback

      Public Overrides Sub
 Commit(mySavedState As IDictionary)
         If myInstallContext.IsParameterTrue("LogtoConsole")
 = True Then
            myInstallContext.LogMessage("The 'Commit' method has
 been called")
         End If
         ' The 'Commit' procedure should be added here.
      End Sub 'Commit

      ' Entry point which delegates to C-style main Private Function
      Public Overloads Shared
 Sub Main()
         Main(System.Environment.GetCommandLineArgs())
      End Sub

      Overloads Shared Sub
 Main(args() As String)
         Dim myInstallObject As New
 InstallContext_Example()
         Dim mySavedState = New Hashtable()

         If args.Length < 2 Then
            ' There are no command line arguments, create an empty 'InstallContext'.
            myInstallObject.myInstallContext = New InstallContext()
         ElseIf args.Length = 2 And args(1)
 = "/?" Then
               ' Display the 'Help' for this utility.
               Console.WriteLine("Specify the '/Logfile' and '/LogtoConsole'
 parameters")
               Console.WriteLine("Example: ")
               Console.WriteLine("InstallContext_InstallContext.exe
 /LogFile=example.log" + _
                                                         " /LogtoConsole=true")
               Return

         Else
            ' Create an InstallContext object with the given parameters.
            Dim commandLine() As String
 = New String(args.Length - 2) {}
            Dim i As Integer
            For i = 1 To args.Length - 1
               commandLine(i-1) = args(i)
            Next i
            myInstallObject.myInstallContext = _
               New InstallContext("/LogFile:example.log",
 commandLine)
         End If

         Try
            ' Call the 'Install' method.
            myInstallObject.Install(mySavedState)

            ' Call the 'Commit' method.
            myInstallObject.Commit(mySavedState)
         Catch
            ' Call the 'Rollback' method.
            myInstallObject.Rollback( mySavedState )
         End Try
      End Sub 'Main
   End Class 'InstallContext_Example
End Namespace 'MyInstallContextNamespace

using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.Collections;
using System.Collections.Specialized;

namespace MyInstallContextNamespace
{
   [RunInstallerAttribute(true)]
   class InstallContext_Example : Installer
   {
      public InstallContext myInstallContext;

      public override void Install( IDictionary
 mySavedState )
      {
         StringDictionary myStringDictionary = myInstallContext.Parameters;
         if( myStringDictionary.Count == 0 )
         {
            Console.WriteLine( "No parameters have been entered in
 the command line "
               +"hence, the install will take place in the
 silent mode" );
         }
         else
         {
            // Check whether the "LogtoConsole" parameter
 has been set.
            if( myInstallContext.IsParameterTrue( "LogtoConsole"
 ) == true )
            {
               // Display the message to the console and add it to the
 logfile.
               myInstallContext.LogMessage( "The 'Install' method has been called"
 );
            }
         }

         // The 'Install procedure should be added here.
      }

      public override void Uninstall( IDictionary
 mySavedState )
      {
         // The 'Uninstall' procedure should be added here.
      }

      public override void Rollback( IDictionary
 mySavedState )
      {
         if( myInstallContext.IsParameterTrue( "LogtoConsole"
 ) == true )
         {
            myInstallContext.LogMessage( "The 'Rollback' method has been called"
 );
         }

         // The 'Rollback' procedure should be added here.
      }

      public override void Commit( IDictionary
 mySavedState )
      {
         if( myInstallContext.IsParameterTrue( "LogtoConsole"
 ) == true )
         {
            myInstallContext.LogMessage( "The 'Commit' method has been called"
 );
         }

         // The 'Commit' procedure should be added here.
      }

      static void Main( string[]
 args )
      {
         InstallContext_Example myInstallObject = new InstallContext_Example();

         IDictionary mySavedState = new Hashtable();

         if( args.Length < 1 )
         {
            // There are no command line arguments, create an empty
 'InstallContext'.
            myInstallObject.myInstallContext = new InstallContext();
         }

         else if( ( args.Length == 1 ) &&
 ( args[ 0 ] == "/?" ) )
         {
            // Display the 'Help' for this utility.
            Console.WriteLine( "Specify the '/Logfile' and '/LogtoConsole' parameters"
 );
            Console.WriteLine( "Example: " );
            Console.WriteLine( "InstallContext_InstallContext.exe /LogFile=example.log"
                                          +" /LogtoConsole=true"
 );
            return;
         }

         else
         {
            // Create an InstallContext object with the given parameters.
            String[] commandLine = new string[
 args.Length ];
            for( int i = 0; i < args.Length;
 i++ )
            {
               commandLine[ i ] = args[ i ];
            }
            myInstallObject.myInstallContext = new InstallContext(
 args[ 0 ], commandLine);
         }

         try
         {
            // Call the 'Install' method.
            myInstallObject.Install( mySavedState );

            // Call the 'Commit' method.
            myInstallObject.Commit( mySavedState );
         }
         catch( Exception )
         {
            // Call the 'Rollback' method.
            myInstallObject.Rollback( mySavedState );
         }
      }
   }
}
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Configuration::Install;
using namespace System::Collections;
using namespace System::Collections::Specialized;

[RunInstallerAttribute(true)]
ref class InstallContext_Example: public Installer
{
public:
   InstallContext^ myInstallContext;
   virtual void Install( IDictionary^ mySavedState ) override
   {
      StringDictionary^ myStringDictionary = myInstallContext->Parameters;
      if ( myStringDictionary->Count == 0 )
      {
         Console::Write( "No parameters have been entered in
 the command line " );
         Console::WriteLine( "hence, the install will take place in
 the silent mode" );
      }
      else
      {
         // Check whether the "LogtoConsole" parameter has
 been set.
         if ( myInstallContext->IsParameterTrue( "LogtoConsole"
 ) )
         {
            // Display the message to the console and add it to the
 logfile.
            myInstallContext->LogMessage( "The 'Install' method has been
 called" );
         }
      }
      // The 'Install procedure should be added here.
   }

   virtual void Uninstall( IDictionary^ mySavedState ) override
   {
      // The 'Uninstall' procedure should be added here.
   }

   virtual void Rollback( IDictionary^ mySavedState ) override
   {
      if ( myInstallContext->IsParameterTrue( "LogtoConsole"
 ) )
      {
         myInstallContext->LogMessage( "The 'Rollback' method has been called"
 );
      }

      // The 'Rollback' procedure should be added here.
   }

   virtual void Commit( IDictionary^ mySavedState ) override
   {
      if ( myInstallContext->IsParameterTrue( "LogtoConsole"
 ) )
      {
         myInstallContext->LogMessage( "The 'Commit' method has been called"
 );
      }

      // The 'Commit' procedure should be added here.
   }
};

int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   InstallContext_Example^ myInstallObject = gcnew InstallContext_Example;
   IDictionary^ mySavedState = gcnew Hashtable;
   if ( args->Length < 2 )
   {
      // There are no command line arguments, create an empty 'InstallContext'.
      myInstallObject->myInstallContext = gcnew InstallContext;
   }
   else
   if ( (args->Length == 2) && (args[ 1 ]->Equals(
 "/?" )) )
   {
      // Display the 'Help' for this utility.
      Console::WriteLine( "Specify the '/Logfile' and '/LogtoConsole' parameters"
 );
      Console::WriteLine( "Example: " );
      Console::WriteLine( "InstallContext_InstallContext.exe /LogFile=example.log
  /LogtoConsole=true" );
      return 0;
   }
   else
   {
      // Create an InstallContext object with the given parameters.
      array<String^>^commandLine = gcnew array<String^>(args->Length
 - 1);
      for ( int i = 0; i < args->Length
 - 1; i++ )
      {
         commandLine[ i ] = args[ i + 1 ];
      }
      myInstallObject->myInstallContext = gcnew InstallContext( args[ 1 ],commandLine
 );
   }

   try
   {
      // Call the 'Install' method.
      myInstallObject->Install( mySavedState );
      
      // Call the 'Commit' method.
      myInstallObject->Commit( mySavedState );
   }
   catch ( Exception^ ) 
   {
      // Call the 'Rollback' method.
      myInstallObject->Rollback( mySavedState );
   }
}
import System.*;
import System.ComponentModel.*;
import System.Configuration.Install.*;
import System.Collections.*;
import System.Collections.Specialized.*;

/** @attribute RunInstallerAttribute(true)
 */
class InstallContextExample extends Installer
{
    public InstallContext myInstallContext;

    public void Install(IDictionary mySavedState)
    {
        StringDictionary myStringDictionary = myInstallContext.get_Parameters();
        if (myStringDictionary.get_Count() == 0) {
            Console.WriteLine("No parameters have been entered in
 the command "
                +"line hence, the install will take place in
 the silent mode");
        }
        else {
            // Check whether the "LogtoConsole" parameter
 has been set.
            if (myInstallContext.IsParameterTrue("LogtoConsole")
 == true) {
                // Display the message to the console and add it
                //to the logfile.
                myInstallContext.LogMessage(
                    "The 'Install' method has been called");
            }
        }
        // The 'Install procedure should be added here.
    } //Install
    
    public void Uninstall(IDictionary mySavedState)
    {
        // The 'Uninstall' procedure should be added here.
    } //Uninstall
    
    public void Rollback(IDictionary mySavedState)
    {
        if (myInstallContext.IsParameterTrue("LogtoConsole")
 == true) {
            myInstallContext.LogMessage(
                "The 'Rollback' method has been called");

            // The 'Rollback' procedure should be added here.
        }
    } //Rollback

    public void Commit(IDictionary mySavedState)
    {
        if (myInstallContext.IsParameterTrue("LogtoConsole")
 == true) {
            myInstallContext.LogMessage("The 'Commit' method has been called");

            // The 'Commit' procedure should be added here.
        }
    } //Commit

    public static void main(String[]
 args)
    {
        InstallContextExample myInstallObject = new InstallContextExample();
        IDictionary mySavedState = new Hashtable();
        if (args.length < 1) {
            // There are no command line arguments, create an empty
            //'InstallContext'.
            myInstallObject.myInstallContext = new InstallContext();
        }
        else {
            if (args.length == 1 && args[0] == "/?")
 {
                // Display the 'Help' for this utility.
                Console.WriteLine(
                    "Specify the '/Logfile' and '/LogtoConsole' parameters");
                Console.WriteLine("Example: ");
                Console.WriteLine("InstallContext_InstallContext.exe"
                    +" /LogFile=example.log" + " /LogtoConsole=true");
                return;
            }
            else {
                // Create an InstallContext object with the given parameters.
                String commandLine[] = new String[args.length];
                for (int i = 0; i < args.length;
 i++) {
                    commandLine.set_Item(i, args[i]);
                }
                myInstallObject.myInstallContext = 
                    new InstallContext(args[0], commandLine);
            } 
        }
        try {
            // Call the 'Install' method.
            myInstallObject.Install(mySavedState);

            // Call the 'Commit' method.
            myInstallObject.Commit(mySavedState);
        }
        catch (System.Exception exp) {
            // Call the 'Rollback' method.
            myInstallObject.Rollback(mySavedState);
        }
    } //main
} //InstallContextExample
継承階層継承階層
System.Object
  System.Configuration.Install.InstallContext
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
InstallContext メンバ
System.Configuration.Install 名前空間
Installer
TransactedInstaller
AssemblyInstaller クラス

InstallContext コンストラクタ ()

InstallContext クラス新しインスタンス初期化します。

名前空間: System.Configuration.Install
アセンブリ: System.Configuration.Install (system.configuration.install.dll 内)
構文構文

Dim instance As New InstallContext
public InstallContext ()
public:
InstallContext ()
public InstallContext ()
public function InstallContext ()
解説解説
使用例使用例
メモメモ

InstallContext コンストラクタオーバーロードされたバージョンいずれか使用方法次の例に示しますその他の例については、個々オーバーロードトピック参照してください

引数なしでプログラム起動すると、空の InstallContext作成されます。

' There are no command line arguments, create an empty 'InstallContext'.
myInstallObject.myInstallContext = New InstallContext()
// There are no command line arguments, create an empty 'InstallContext'.
myInstallObject.myInstallContext = new InstallContext();
// There are no command line arguments, create an empty 'InstallContext'.
myInstallObject->myInstallContext = gcnew InstallContext;
// There are no command line arguments, create an empty
//'InstallContext'.
myInstallObject.myInstallContext = new InstallContext();
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
InstallContext クラス
InstallContext メンバ
System.Configuration.Install 名前空間

InstallContext コンストラクタ (String, String[])

InstallContext クラス新しインスタンス初期化しインストール用のログ ファイル作成します

名前空間: System.Configuration.Install
アセンブリ: System.Configuration.Install (system.configuration.install.dll 内)
構文構文

Public Sub New ( _
    logFilePath As String, _
    commandLine As String() _
)
Dim logFilePath As String
Dim commandLine As String()

Dim instance As New InstallContext(logFilePath,
 commandLine)
public InstallContext (
    string logFilePath,
    string[] commandLine
)
public:
InstallContext (
    String^ logFilePath, 
    array<String^>^ commandLine
)
public InstallContext (
    String logFilePath, 
    String[] commandLine
)
public function InstallContext (
    logFilePath : String, 
    commandLine : String[]
)

パラメータ

logFilePath

インストール用のログ ファイルパスログ ファイル作成しない場合null 参照 (Visual Basic では Nothing)。

commandLine

セットアップ プログラム実行時入力されコマンド ライン パラメータ入力されなかった場合null 参照 (Visual Basic では Nothing)。

解説解説
使用例使用例

この例は、InstallContext クラス概要紹介されているクラスの例からの抜粋です。

"/LogFile" および "/LogtoConsole" を指定した場合それぞれの引数を InstallContext に渡してInstallContext作成されます。

' Create an InstallContext object with the given parameters.
Dim commandLine() As String
 = New String(args.Length - 2) {}
Dim i As Integer
For i = 1 To args.Length - 1
   commandLine(i-1) = args(i)
Next i
myInstallObject.myInstallContext = _
   New InstallContext("/LogFile:example.log",
 commandLine)
// Create an InstallContext object with the given parameters.
String[] commandLine = new string[ args.Length
 ];
for( int i = 0; i < args.Length; i++ )
{
   commandLine[ i ] = args[ i ];
}
myInstallObject.myInstallContext = new InstallContext( args[ 0
 ], commandLine);
// Create an InstallContext object with the given parameters.
array<String^>^commandLine = gcnew array<String^>(args->Length - 1);
for ( int i = 0; i < args->Length - 1;
 i++ )
{
   commandLine[ i ] = args[ i + 1 ];
}
myInstallObject->myInstallContext = gcnew InstallContext( args[ 1 ],commandLine
 );
// Create an InstallContext object with the given parameters.
String commandLine[] = new String[args.length];
for (int i = 0; i < args.length; i++) {
    commandLine.set_Item(i, args[i]);
}
myInstallObject.myInstallContext = 
    new InstallContext(args[0], commandLine);
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
InstallContext クラス
InstallContext メンバ
System.Configuration.Install 名前空間
Parameters
LogMessage

InstallContext コンストラクタ

InstallContext クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

InstallContext クラス
InstallContext メンバ
System.Configuration.Install 名前空間

InstallContext プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Parameters InstallUtil.exe の実行時入力されコマンド ライン パラメータ取得します
参照参照

関連項目

InstallContext クラス
System.Configuration.Install 名前空間
Installer
TransactedInstaller
AssemblyInstaller クラス

InstallContext メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

InstallContext クラス
System.Configuration.Install 名前空間
Installer
TransactedInstaller
AssemblyInstaller クラス

InstallContext メンバ

現在のインストールに関する情報格納します

InstallContext データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Parameters InstallUtil.exe の実行時入力されコマンド ライン パラメータ取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

InstallContext クラス
System.Configuration.Install 名前空間
Installer
TransactedInstaller
AssemblyInstaller クラス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「InstallContext」の関連用語

InstallContextのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



InstallContextのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS