Installutil.exe (安裝程式工具)Installutil.exe (Installer Tool)

安裝程式工具是一種命令列公用程式,可讓您透過執行指定之組件中的安裝程式元件,來安裝和解除安裝伺服器資源。The Installer tool is a command-line utility that allows you to install and uninstall server resources by executing the installer components in specified assemblies. 這個工具可以與 System.Configuration.Install 命名空間中的類別一起使用。This tool works in conjunction with classes in the System.Configuration.Install namespace.

此工具會自動與 Visual Studio 一起安裝。This tool is automatically installed with Visual Studio. 若要執行這項工具,請使用 [Visual Studio 開發人員命令提示字元] (或 Windows 7 中的 [Visual Studio 命令提示字元])。To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7). 如需詳細資訊,請參閱命令提示字元For more information, see Command Prompts.

在命令提示字元下輸入下列命令:At the command prompt, type the following:

語法Syntax

installutil [/u[ninstall]] [options] assembly [[options] assembly] ...

參數Parameters

引數Argument 說明Description
assembly 要執行安裝程式元件之組件的檔案名稱。The file name of the assembly in which to execute the installer components. 如果您要使用 /AssemblyName 選項指定組件的強式名稱,請略過此參數。Omit this parameter if you want to specify the assembly's strong name by using the /AssemblyName option.

選項Options

選項Option 描述Description
/h[elp]

-或--or-

/?
顯示工具的命令語法和選項。Displays command syntax and options for the tool.
/help assembly/help assembly

-或--or-

/? assembly/? assembly
顯示指定之組件中的個別安裝程式所辨識的其他選項,以及 InstallUtil.exe 的指令語法和選項。Displays additional options recognized by individual installers within the specified assembly, along with command syntax and options for InstallUtil.exe. 這個選項會將每個安裝程式元件之 Installer.HelpText 屬性所傳回的文字加入至 InstallUtil.exe 的説明文字。This option adds the text returned by each installer component's Installer.HelpText property to the help text of InstallUtil.exe.
/AssemblyName "assemblyName/AssemblyName "assemblyName

,Version=major.minor.build.revision,Version=major.minor.build.revision

,Culture=locale,Culture=locale

,PublicKeyToken=publicKeyToken",PublicKeyToken=publicKeyToken"
指定組件的強式名稱,必須在全域組件快取中登錄此名稱。Specifies the strong name of an assembly, which must be registered in the global assembly cache. 您必須利用組件的版本、文化特性 (Culture) 和公開金鑰語彙基元 (Token) 以完整限定組件名稱。The assembly name must be fully qualified with the version, culture, and public key token of the assembly. 必須以引號括住完整名稱。The fully qualified name must be surrounded by quotes.

例如,"myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0" 就是完整的組件名稱。For example, "myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0" is a fully qualified assembly name.
/InstallStateDir=[ directoryName ]/InstallStateDir=[ directoryName ] 指定 .InstallState 檔案的目錄,其中包含用於解除安裝組件的資料。Specifies the directory of the .InstallState file that contains the data used to uninstall the assembly. 預設是包含組件的目錄。The default is the directory that contains the assembly.
/LogFile=[filename]/LogFile=[filename] 指定記錄安裝進度的記錄檔名稱。Specifies the name of the log file where installation progress is recorded. 預設情況下,如果省略 /LogFile 選項,則會建立名為 assemblyname.InstallLog 的記錄檔。By default, if the /LogFile option is omitted, a log file named assemblyname.InstallLog is created. 如果省略 filename,則不會產生任何記錄檔。If filename is omitted, no log file is generated.
/LogToConsole={true|false}/LogToConsole={true|false} 如果為 true,則會在主控台顯示輸出。If true, displays output to the console. 如果為 false (預設值),則隱藏對主控台的輸出。If false (the default), suppresses output to the console.
/ShowCallStack 如果在安裝期間的任何時間點上發生例外狀況,則將呼叫堆疊輸出到記錄檔。Outputs the call stack to the log file if an exception occurs at any point during installation.
/u[ninstall]/u[ninstall] 解除安裝指定的組件。Uninstalls the specified assemblies. 不同於其他選項,/u 會套用至所有組件 (與選項出現在命令列上的位置無關)。Unlike the other options, /u applies to all assemblies regardless of where the option appears on the command line.

其他安裝程式選項Additional Installer Options

組件中使用的個別安裝程式可能會辨識列在選項區段以外的選項。Individual installers used within an assembly may recognize options in addition to those listed in the Options section. 若要了解這些選項,請在命令列上使用組件路徑搭配 /?/help 選項以執行 InstallUtil.exe。To learn about these options, run InstallUtil.exe with the paths of the assemblies on the command line along with the /? or /help option. 若要指定這些選項,請在命令列上將這些選項與 InstallUtil.exe 辨識的選項包含在一起。To specify these options, you include them on the command line along with the options recognized by InstallUtil.exe.

注意

個別安裝程式元件所支援之選項上的說明文字由 Installer.HelpText 屬性傳回。Help text on the options supported by individual installer components is returned by the Installer.HelpText property. 已經在命令列上輸入的個別選項可透過程式設計方式從 Installer.Context 屬性中存取。The individual options that have been entered on the command line are accessible programmatically from the Installer.Context property.

所有選項和命令列參數皆會寫入安裝記錄檔。All options and command-line parameters are written to the installation log file. 但是,如果您使用某些安裝程式元件可識別的 /Password 參數,則會以八個星號 (*) 取代密碼資訊,因此密碼不會出現在記錄檔中。However, if you use the /Password parameter, which is recognized by some installer components, the password information will be replaced by eight asterisks (*) and will not appear in the log file.

重要

在某些情況下,傳遞給安裝程式的參數可能包含機密或可識別個人身分的資訊,這些資訊預設是寫入到純文字的記錄檔。In some cases, parameters passed to the installer may include sensitive or personally identifiable information, which, by default, is written to a plain text log file. 若要防止這個行為,您可以在命令列上的 Installutil.exe 後面指定 /LogFile= (不含 filename 引數) 以隱藏記錄檔。To prevent this behavior, you can suppress the log file by specifying /LogFile= (with no filename argument) after Installutil.exe on the command line.

備註Remarks

.NET Framework 應用程式由傳統的程式檔和關聯的資源組成,例如訊息佇列、事件記錄檔,以及部署應用程式時所必須建立的效能計數器。.NET Framework applications consist of traditional program files and associated resources, such as message queues, event logs, and performance counters that must be created when the application is deployed. 安裝應用程式時,您可以使用組件的安裝元件來建立這些資源,並在解除安裝應用程式時移除它們。You can use an assembly's installer components to create these resources when your application is installed and to remove them when your application is uninstalled. Installutil.exe 會偵測並執行這些安裝程式元件。Installutil.exe detects and executes these installer components.

您可以在相同命令列上指定多個組件。You can specify multiple assemblies on the same command line. 任何出現在組件名稱之前的選項都會套用到該組件的安裝。Any option that occurs before an assembly name applies to that assembly's installation. 除了 /u/AssemblyName 之外,選項可以累積但不可覆寫。Except for /u and /AssemblyName, options are cumulative but overridable. 也就是說,除非以新的值指定選項,否則為一個組件指定的選項會套用到所有後續的組件。That is, options specified for one assembly apply to all subsequent assemblies unless the option is specified with a new value.

如果對組件執行 Installutil.exe 而沒有指定任何選項的話,它會將下列三個檔案放置到組件的目錄中:If you run Installutil.exe against an assembly without specifying any options, it places the following three files into the assembly's directory:

  • InstallUtil.InstallLog:包含安裝進度的一般說明。InstallUtil.InstallLog - Contains a general description of the installation progress.

  • assemblyname.InstallLog - 包含安裝程序認可階段的特定資訊。assemblyname.InstallLog - Contains information specific to the commit phase of the installation process. 如需關於認可階段的詳細資訊,請參閱 Commit 方法。For more information about the commit phase, see the Commit method.

  • assemblyname.InstallState - 包含用來解除安裝組件的資料。assemblyname.InstallState - Contains data used to uninstall the assembly.

Installutil.exe 使用反射來檢查指定的組件並找到所有 Installer 類型,這些類型的 System.ComponentModel.RunInstallerAttribute 屬性設定為 trueInstallutil.exe uses reflection to inspect the specified assemblies and to find all Installer types that have the System.ComponentModel.RunInstallerAttribute attribute set to true. 然後工具會在 Installer.Install 類型的每個執行個體上執行 Installer.UninstallInstaller 方法。The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type. Installutil.exe 會以交易方式執行安裝;也就是說,如果其中一個組件安裝失敗,便會復原所有其他組件的安裝。Installutil.exe performs installation in a transactional manner; that is, if one of the assemblies fails to install, it rolls back the installations of all other assemblies. 解除安裝不是可異動的。Uninstall is not transactional.

Installutil.exe 無法安裝或解除安裝延遲簽署的組件,但是可以安裝或解除安裝強式命名的組件。Installutil.exe cannot install or uninstall delay-signed assemblies, but it can install or uninstall strong-named assemblies.

從 .NET Framework 2.0 版開始,32 位元版本的通用語言執行平台 (CLR) 僅會隨附於 32 位元版本的安裝程式工具,但是 64 位元版本的 CLR 則會隨附於 32 位元和 64 位元版本的安裝程式工具。Starting with the .NET Framework version 2.0, the 32-bit version of the common language runtime (CLR) ships with only the 32-bit version of the Installer tool, but the 64-bit version of the CLR ships with both 32-bit and 64-bit versions of the Installer tool. 當您使用 64 位元的 CLR 時,請使用 32 位元的安裝程式工具來安裝 32 位元的組件,並使用 64 位元的安裝程式工具來安裝 64 位元和 Microsoft Intermediate Language (MSIL) 的組件。When using the 64-bit CLR, use the 32-bit Installer tool to install 32-bit assemblies, and the 64-bit Installer tool to install 64-bit and Microsoft intermediate language (MSIL) assemblies. 這兩種版本的安裝程式工具會有相同的行為方式。Both versions of the Installer tool behave the same.

您不能使用 Installutil.exe 部署使用 C++ 建立的 Windows 服務,因為 Installutil.exe 無法辨識由 C++ 編譯器產生的內嵌機器碼。You cannot use Installutil.exe to deploy a Windows service that was created by using C++, because Installutil.exe cannot recognize the embedded native code that is produced by the C++ compiler. 如果您嘗試使用 Installutil.exe 部署 C++ Windows 服務,就會擲回類似 BadImageFormatException 的例外狀況。If you try to deploy a C++ Windows service with Installutil.exe, an exception such as BadImageFormatException will be thrown. 若要處理這種案例,請將服務程式碼移至 C++ 模組,然後以 C# 或 Visual Basic 撰寫安裝程式物件。To work with this scenario, move the service code to a C++ module, and then write the installer object in C# or Visual Basic.

範例Examples

下列命令會顯示 InstallUtil.exe 命令語法及選項的描述。The following command displays a description of the command syntax and options for InstallUtil.exe.

installutil /?

下列命令會顯示 InstallUtil.exe 命令語法及選項的描述。The following command displays a description of the command syntax and options for InstallUtil.exe. 如果已將說明文字指派給安裝程式的 Installer.HelpText 屬性,還會顯示 myAssembly.exe 中的安裝程式元件所支援的選項描述和清單。It also displays a description and list of options supported by the installer components in myAssembly.exe if help text has been assigned to the installer's Installer.HelpText property.

installutil /? myAssembly.exe

下列命令會執行 myAssembly.exe 組件中的安裝程式元件。The following command executes the installer components in the assembly myAssembly.exe.

installutil myAssembly.exe

下列命令會使用 /AssemblyName 參數和完整名稱,執行組件中的安裝程式元件。The following command executes the installer components in an assembly by using the /AssemblyName switch and a fully qualified name.

installutil /AssemblyName "myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0"

下列命令會執行檔案名稱及強式名稱所指定之組件中的安裝程式元件。The following command executes the installer components in an assembly specified by file name and in an assembly specified by strong name. 請注意,所有依檔案名稱指定的組件必須在命令列中以強式名稱指定的組件之前,因為不可覆寫 /AssemblyName 選項。Note that all assemblies specified by file name must precede assemblies specified by strong name on the command line, because the /AssemblyName option cannot be overridden.

installutil myAssembly.exe /AssemblyName "myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0"

下列命令會執行 myAssembly.exe 組件中的解除安裝程式元件。The following command executes the uninstaller components in the assembly myAssembly.exe.

installutil /u myAssembly.exe

下列命令會執行組件 myAssembly1.exemyAssembly2.exe 中的解除安裝程式元件。The following command executes the uninstaller components in the assemblies myAssembly1.exe and myAssembly2.exe.

installutil myAssembly1.exe /u myAssembly2.exe

因為 /u 選項在命令列中的位置並不重要,因此這會等於下列指令。Because the position of the /u option on the command line is not important, this is equivalent to the following command.

installutil /u myAssembly1.exe myAssembly2.exe

下列命令會執行 myAssembly.exe 組件中的安裝程式,並指定將進度資訊寫入 myLog.InstallLogThe following command executes the installers in the assembly myAssembly.exe and specifies that progress information will be written to myLog.InstallLog.

installutil /LogFile=myLog.InstallLog myAssembly.exe

下列命令會執行組件 myAssembly.exe 中的安裝程式、指定要將進度資訊寫入 myLog.InstallLog,然後使用安裝程式的自訂 /reg 選項指定要對系統登錄進行更新。The following command executes the installers in the assembly myAssembly.exe, specifies that progress information should be written to myLog.InstallLog, and uses the installers' custom /reg option to specify that updates should be made to the system registry.

installutil /LogFile=myLog.InstallLog /reg=true myAssembly.exe

下列命令會執行組件 myAssembly.exe 中的安裝程式、使用安裝程式的自訂 /email 選項指定使用者的電子郵件地址,並隱藏對記錄檔的輸出。The following command executes the installers in the assembly myAssembly.exe, uses the installer's custom /email option to specify the user's email address, and suppresses output to the log file.

installutil /LogFile= /email=admin@mycompany.com myAssembly.exe

下列命令會將 myAssembly.exe 的安裝進度寫入到 myLog.InstallLog,並且將 myTestAssembly.exe 的進度寫入到 myTestLog.InstallLogThe following command writes the installation progress for myAssembly.exe to myLog.InstallLog and writes the progress for myTestAssembly.exe to myTestLog.InstallLog.

installutil /LogFile=myLog.InstallLog myAssembly.exe /LogFile=myTestLog.InstallLog myTestAssembly.exe

另請參閱See also