InstallContext Class
Contains information about the current installation.
Assembly: System.Configuration.Install (in System.Configuration.Install.dll)
Typically, an InstallContext is created by an installation executable, such as InstallUtil.exe, that installs assemblies. The installation program invokes the InstallContext constructor, passing it the default log-file path and command-line parameters.
Prior to calling its Install, Commit, Rollback, or Uninstall methods, the installation program sets the Context property of an Installer to the instance of InstallContext. Before calling these methods, an Installer that contains an installer collection in the Installers property sets the Context property of each contained installer.
The Parameters property contains a parsed version of the command line that is entered to run the installation executable. The property contains information such as the path to a log file, whether to display log information on the console, and whether to show a user interface during the installation. Call the IsParameterTrue method to find out whether a command-line parameter is true.
Use the LogMessage method to write status messages to the installation log file and the console.
The following example demonstrates the InstallContext constructors, the Parameters property and the LogMessage and IsParameterTrue methods of the InstallContext class.
When the Install method of the installer is called, it checks for parameters from the command line. Depending on that, it displays the progress messages onto the console and also saves it to the specified log file.
When the program is invoked without any arguments, an empty InstallContext is created. When "/LogFile" and "/LogtoConsole" are specified, the InstallContext is created by passing the respective arguments to 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
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.