- Installutil.exe (Installer Tool)
- Syntax
- Parameters
- Options
- Additional Installer Options
- Remarks
- Examples
- How to: Add Installers to Your Service Application
- To add installers to your service application
- Практическое руководство. Установка и удаление служб Windows How to: Install and uninstall Windows services
- Установка с помощью программы InstallUtil.exe Install using InstallUtil.exe utility
- Удаление с помощью служебной программы InstallUtil.exe Uninstall using InstallUtil.exe utility
- Установка с помощью PowerShell Install using PowerShell
- Удаление с помощью PowerShell Uninstall using PowerShell
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. This tool works in conjunction with classes in the System.Configuration.Install namespace.
This tool is automatically installed with Visual Studio. To run the tool, use Visual Studio Developer Command Prompt or Visual Studio Developer PowerShell.
At the command prompt, type the following:
Syntax
Parameters
Argument | Description |
---|---|
assembly | The file name of the assembly in which to execute the installer components. Omit this parameter if you want to specify the assembly’s strong name by using the /AssemblyName option. |
Options
Option | Description |
---|---|
/h[elp] |
/?
/? assembly
,PublicKeyToken=publicKeyToken«
For example, «myAssembly, Culture=neutral, PublicKeyToken=0038abc9deabfle5, Version=4.0.0.0» is a fully qualified assembly name.
Additional Installer Options
Individual installers used within an assembly may recognize options in addition to those listed in the Options section. To learn about these options, run InstallUtil.exe with the paths of the assemblies on the command line along with the /? or /help option. To specify these options, you include them on the command line along with the options recognized by InstallUtil.exe.
Help text on the options supported by individual installer components is returned by the Installer.HelpText property. 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. 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. 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 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 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. 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.
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 — Contains a general description of the installation progress.
assemblyname.InstallLog — Contains information specific to the commit phase of the installation process. For more information about the commit phase, see the Commit method.
assemblyname.InstallState — Contains data used to uninstall the assembly.
Installutil.exe uses reflection to inspect the specified assemblies and to find all Installer types that have the System.ComponentModel.RunInstallerAttribute attribute set to true . The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type. 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 cannot install or uninstall delay-signed assemblies, but it can install or uninstall strong-named assemblies.
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. 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.
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. If you try to deploy a C++ Windows service with Installutil.exe, an exception such as BadImageFormatException will be thrown. 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
The following command displays a description of the command syntax and options for InstallUtil.exe.
The following command displays a description of the command syntax and options for InstallUtil.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.
The following command executes the installer components in the assembly myAssembly.exe .
The following command executes the installer components in an assembly by using the /AssemblyName switch and a fully qualified name.
The following command executes the installer components in an assembly specified by file name and in an assembly specified by strong name. 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.
The following command executes the uninstaller components in the assembly myAssembly.exe .
The following command executes the uninstaller components in the assemblies myAssembly1.exe and myAssembly2.exe .
Because the position of the /u option on the command line is not important, this is equivalent to the following command.
How to: Add Installers to Your Service Application
Visual Studio ships installation components that can install resources associated with your service applications. Installation components register an individual service on the system to which it is being installed and let the Services Control Manager know that the service exists. When you work with a service application, you can select a link in the Properties window to automatically add the appropriate installers to your project.
Property values for your service are copied from the service class to the installer class. If you update the property values on the service class, they are not automatically updated in the installer.
When you add an installer to your project, a new class (which, by default, is named ProjectInstaller ) is created in the project, and instances of the appropriate installation components are created within it. This class acts as a central point for all of the installation components your project needs. For example, if you add a second service to your application and click the Add Installer link, a second installer class is not created; instead, the necessary additional installation component for the second service is added to the existing class.
You do not need to do any special coding within the installers to make your services install correctly. However, you may occasionally need to modify the contents of the installers if you need to add special functionality to the installation process.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Personalize the Visual Studio IDE.
To add installers to your service application
In Solution Explorer, access Design view for the service for which you want to add an installation component.
Click the background of the designer to select the service itself, rather than any of its contents.
With the designer in focus, right-click, and then click Add Installer.
A new class, ProjectInstaller , and two installation components, ServiceProcessInstaller and ServiceInstaller, are added to your project, and property values for the service are copied to the components.
Click the ServiceInstaller component and verify that the value of the ServiceName property is set to the same value as the ServiceName property on the service itself.
To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.
Value | Result |
---|---|
Manual | The service must be manually started after installation. For more information, see How to: Start Services. |
Automatic | The service will start by itself whenever the computer reboots. |
Disabled | The service cannot be started. |
To determine the security context in which your service will run, click the ServiceProcessInstaller component and set the appropriate property values. For more information, see How to: Specify the Security Context for Services.
Override any methods for which you need to perform custom processing.
Perform steps 1 through 7 for each additional service in your project.
For each additional service in your project, you must add an additional ServiceInstaller component to the project’s ProjectInstaller class. The ServiceProcessInstaller component added in step three works with all of the individual service installers in the project.
Практическое руководство. Установка и удаление служб Windows How to: Install and uninstall Windows services
Если вы разрабатываете службу Windows с помощью .NET Framework, вы можете быстро установить приложение службы с помощью служебной программы командной строки InstallUtil.exe или PowerShell. If you’re developing a Windows service with the .NET Framework, you can quickly install your service app by using the InstallUtil.exe command-line utility or PowerShell. Если вы являетесь разработчиком и хотите создать службу Windows, которую пользователи могут устанавливать и удалять, можно использовать набор инструментов WiX или коммерческие средства, такие как Advanced Installer, InstallShield или другие. Developers who want to release a Windows service that users can install and uninstall can use the free WiX Toolset or commercial tools like Advanced Installer, InstallShield, or others. См. сведения о создании пакета установщика (классическое приложение Windows). For more information, see Create an installer package (Windows desktop).
Если вы хотите удалить службу на своем компьютере, не выполняйте процедуру, описанную в этой статье. If you want to uninstall a service from your computer, don’t follow the steps in this article. Вместо этого определите, какая программа (или программный пакет) установила эту службу, а затем выберите Приложения в параметрах, чтобы удалить эту программу. Instead, find out which program or software package installed the service, and then choose Apps in Settings to uninstall that program. Следует отметить, что многие службы являются составной частью ОС Windows. Если их удалить, это может привести к нестабильной работе системы. Note that many services are integral parts of Windows; if you remove them, you might cause system instability.
Чтобы использовать процедуру, описанную в этой статье, сначала необходимо добавить установщик службы в свою службу Windows. To use the steps in this article, you first need to add a service installer to your Windows service. Дополнительные сведения см. в разделе Пошаговое руководство: создание диспетчера служб Windows. For more information, see Walkthrough: Creating a Windows service app.
Проекты служб Windows нельзя запускать непосредственно из среды разработки Visual Studio путем нажатия клавиши F5. You can’t run Windows service projects directly from the Visual Studio development environment by pressing F5. Перед запуском проекта необходимо установить службу в проекте. Before you can run the project, you must install the service in the project.
Запустите обозреватель сервера и убедитесь, что служба установлена или удалена. You can use Server Explorer to verify that you’ve installed or uninstalled your service.
Установка с помощью программы InstallUtil.exe Install using InstallUtil.exe utility
В меню Пуск выберите каталог Visual Studio и затем Командная строка разработчика для VS . From the Start menu, select the Visual Studio directory, then select Developer Command Prompt for VS .
Появится командная строка разработчика для Visual Studio. The Developer Command Prompt for Visual Studio appears.
Откройте каталог, где находится скомпилированный исполняемый файл вашего проекта. Access the directory where your project’s compiled executable file is located.
Запустите InstallUtil.exe из командной строки, указав исполняемый файл проекта в качестве параметра: Run InstallUtil.exe from the command prompt with your project’s executable as a parameter:
Если вы используете командную строку разработчика для Visual Studio, системный путь должен указывать на файл InstallUtil.exe. If you’re using the Developer Command Prompt for Visual Studio, InstallUtil.exe should be on the system path. Если это не так, можно добавить его в путь или использовать полный путь для его вызова. Otherwise, you can add it to the path, or use the fully qualified path to invoke it. Этот инструмент устанавливается вместе с платформой .NET Framework в папку %WINDIR%\Microsoft.NET\Framework[64]\ . This tool is installed with the .NET Framework in %WINDIR%\Microsoft.NET\Framework[64]\ .
Пример: For example:
- Для 32-разрядной версии .NET Framework 4 или 4.5 и более поздних версий: если каталог установки Windows — C:\Windows, по умолчанию используется путь C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe. For the 32-bit version of the .NET Framework 4 or 4.5 and later, if your Windows installation directory is C:\Windows, the default path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.
- Для 64-разрядной версии .NET Framework 4 или 4.5 и более поздних версий: по умолчанию используется путь C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe. For the 64-bit version of the .NET Framework 4 or 4.5 and later, the default path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe.
Удаление с помощью служебной программы InstallUtil.exe Uninstall using InstallUtil.exe utility
В меню Пуск выберите каталог Visual Studio и затем Командная строка разработчика для VS . From the Start menu, select the Visual Studio directory, then select Developer Command Prompt for VS .
Появится командная строка разработчика для Visual Studio. The Developer Command Prompt for Visual Studio appears.
Запустите InstallUtil.exe из командной строки, указав выходные данные проекта в качестве параметра: Run InstallUtil.exe from the command prompt with your project’s output as a parameter:
После удаления исполняемого файла для службы сама служба может по-прежнему присутствовать в реестре. After the executable for a service is deleted, the service might still be present in the registry. В этом случае удалить запись службы из реестра можно с помощью команды sc delete. If that’s the case, use the command sc delete to remove the entry for the service from the registry.
Установка с помощью PowerShell Install using PowerShell
В меню Пуск выберите Каталог Windows PowerShell и Windows PowerShell. From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.
Откройте каталог, где находится скомпилированный исполняемый файл вашего проекта. Access the directory where your project’s compiled executable file is located.
Выполните командлет New-Service, указав в качестве параметров выходные данные проекта и имя службы. Run the New-Service cmdlet with the with your project’s output and a service name as parameters:
Удаление с помощью PowerShell Uninstall using PowerShell
В меню Пуск выберите Каталог Windows PowerShell и Windows PowerShell. From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.
Выполните командлет Remove-Service, указав в качестве параметра имя службы. Run the Remove-Service cmdlet with the name of your service as parameter:
После удаления исполняемого файла для службы сама служба может по-прежнему присутствовать в реестре. After the executable for a service is deleted, the service might still be present in the registry. В этом случае удалить запись службы из реестра можно с помощью команды sc delete. If that’s the case, use the command sc delete to remove the entry for the service from the registry.