現在のインストールに関する情報を格納します。
この型のすべてのメンバの一覧については、InstallContext メンバ を参照してください。
System.Object
System.Configuration.Install.InstallContext
Public Class InstallContext
[C#]
public class InstallContext
[C++]
public __gc class InstallContext
[JScript]
public class InstallContext
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
通常、 InstallContext は、アセンブリをインストールする InstallUtil.exe などのインストール実行可能ファイルによって作成されます。セットアップ プログラム (インストール実行可能ファイル) は、既定のログ ファイル パスとコマンド ライン パラメータを渡して InstallContext コンストラクタを呼び出します。
セットアップ プログラムは、 Install 、 Commit 、 Rollback 、または Uninstall の各メソッドを呼び出す前に、 Installer の Context プロパティとして InstallContext のインスタンスを設定します。これらのメソッドを呼び出す前に、 Installers プロパティのインストーラ コレクションを格納している Installer が、それぞれが格納している各インストーラの Context プロパティを設定します。
Parameters プロパティは、インストール実行可能ファイルの実行時に入力されたコマンド ラインを解析した結果を格納します。このプロパティには、ログ ファイルへのパス、コンソールにログ情報を表示するかどうか、インストール中にユーザー インターフェイスを表示するかどうかなどの情報が格納されます。コマンド ライン パラメータが true かどうかを確認するには、 IsParameterTrue メソッドを呼び出します。
ステータス メッセージをインストール ログ ファイルとコンソールに書き込むには、 LogMessage メソッドを使用します。
使用例
[Visual Basic, C#, C++] InstallContext クラスの InstallContext コンストラクタ、 Parameters プロパティ、および LogMessage と IsParameterTrue の各メソッドの例を次に示します。
[Visual Basic, C#, C++] インストーラの Install メソッドが呼び出されると、コマンド ラインのパラメータがチェックされます。それに応じて、進行状況のメッセージをコンソールに表示し、指定したログ ファイルにも保存します。
[Visual Basic, C#, C++] 引数なしでプログラムを起動すると、空の 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
[C#]
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 );
}
}
}
}
[C++]
#using <mscorlib.dll>
#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)]
__gc class InstallContext_Example : public Installer {
public:
InstallContext* myInstallContext;
void Install(IDictionary* mySavedState) {
StringDictionary* myStringDictionary = myInstallContext->Parameters;
if (myStringDictionary->Count == 0) {
Console::Write(S"No parameters have been entered in the command line ");
Console::WriteLine(S"hence, the install will take place in the silent mode");
} else {
// Check whether the "LogtoConsole" parameter has been set.
if (myInstallContext->IsParameterTrue(S"LogtoConsole")) {
// Display the message to the console and add it to the logfile.
myInstallContext->LogMessage(S"The 'Install' method has been called");
}
}
// The 'Install procedure should be added here.
}
void Uninstall(IDictionary* mySavedState) {
// The 'Uninstall' procedure should be added here.
}
void Rollback(IDictionary* mySavedState) {
if (myInstallContext->IsParameterTrue(S"LogtoConsole")) {
myInstallContext->LogMessage(S"The 'Rollback' method has been called");
}
// The 'Rollback' procedure should be added here.
}
void Commit(IDictionary* mySavedState) {
if (myInstallContext->IsParameterTrue(S"LogtoConsole")) {
myInstallContext->LogMessage(S"The 'Commit' method has been called");
}
// The 'Commit' procedure should be added here.
}
};
int main() {
String* args[] = Environment::GetCommandLineArgs();
InstallContext_Example* myInstallObject = new InstallContext_Example();
IDictionary* mySavedState = new Hashtable();
if (args->Length < 2) {
// There are no command line arguments, create an empty 'InstallContext'.
myInstallObject->myInstallContext = new InstallContext();
} else if ((args->Length == 2) && (args[1]->Equals(S"/?"))) {
// Display the 'Help' for this utility.
Console::WriteLine(S"Specify the '/Logfile' and '/LogtoConsole' parameters");
Console::WriteLine(S"Example: ");
Console::WriteLine(S"InstallContext_InstallContext.exe /LogFile=example.log /LogtoConsole=true");
return 0;
} else {
// Create an InstallContext object with the given parameters.
String* commandLine[] = new String*[args->Length - 1];
for (int i = 0; i < args->Length - 1; i++) {
commandLine->Item[i] = args->Item[i + 1];
}
myInstallObject->myInstallContext = new 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);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Configuration.Install
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Configuration.Install (System.Configuration.Install.dll 内)
参照
InstallContext メンバ | System.Configuration.Install 名前空間 | Installer | TransactedInstaller | AssemblyInstaller