ServiceProcessInstaller クラス
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)


ServiceProcessInstaller は、実行可能ファイル内のすべてのサービスに対して同じ作業を行います。このクラスは、インストール ユーティリティで、インストールするサービスに関連付けられたレジストリ値を書き込むために使用されます。
サービスをインストールするには、Installer から継承するプロジェクト インストーラ クラスを作成し、そのクラスの RunInstallerAttribute を true に設定します。プロジェクト内では、サービス アプリケーションごとに 1 つの ServiceProcessInstaller インスタンス、およびアプリケーション内の各サービスにつき 1 つの ServiceInstaller インスタンスをインスタンス化します。最後に、ServiceProcessInstaller インスタンスおよび ServiceInstaller インスタンスをプロジェクト インストーラ クラスに追加します。
InstallUtil.exe を実行すると、ユーティリティは、RunInstallerAttribute が true に設定されているクラスをサービス アセンブリ内で検索します。プロジェクト インストーラに関連付けられている Installers コレクションにクラスを追加することにより、サービス アセンブリにクラスを追加します。RunInstallerAttribute が false の場合、ユーティリティはプロジェクト インストーラを無視します。
ServiceProcessInstaller のインスタンスについては、プロパティを変更して、ログオンしたユーザー以外のアカウントでサービス アプリケーションを実行するように指定できます。サービスを実行するときに必要な特定の Username と Password の組み合わせを指定できます。また、Account を使用して、コンピュータのシステム アカウント、ローカル サービス アカウントやネットワーク サービス アカウント、またはユーザー アカウントでサービスを実行するように指定できます。
![]() |
---|
通常、コード内の ServiceInstaller ではこのメソッドを呼び出しません。このメソッドを呼び出すのは、一般的にインストール ユーティリティだけです。インストール ユーティリティは、インストール プロセス中に、ServiceProcessInstaller.Install メソッドと ServiceInstaller.Install メソッドを自動的に呼び出します。必要に応じて、インストール済みのすべてのコンポーネントで Rollback (または ServiceInstaller.Rollback) を呼び出すことによって、エラーを回復します。
アプリケーションのインストール ルーチンは、既にインストールされているコンポーネントに関する情報を、プロジェクト インストーラの Installer.Context を使用して自動的に維持します。この状態情報は、ServiceProcessInstaller インスタンスとして継続的に更新されます。各 ServiceInstaller インスタンスは、ユーティリティでインストールされます。通常、コードではこの状態情報を明示的に変更する必要はありません。
ServiceProcessInstaller をインスタンス化すると、基本クラスのコンストラクタ ComponentInstaller が呼び出されます。

Installer から継承される、MyProjectInstaller という名前のプロジェクト インストーラを作成する例を次に示します。この例では、2 つのサービス "Hello-World Service 1" および "Hello-World Service 2" を含んだ、サービスの実行可能ファイルがあることを前提にしています。インストール ユーティリティによって呼び出される MyProjectInstaller のコンストラクタ内では、これらの各サービスに対して ServiceInstaller オブジェクトが作成され、実行可能ファイルに対して ServiceProcessInstaller が作成されます。インストール ユーティリティで MyProjectInstaller を有効なインストーラとして認識できるように、RunInstallerAttribute 属性は true に設定されます。
インストーラが Installers コレクションに追加される前に、オプションのプロパティがプロセス インストーラおよびサービス インストーラに設定されます。インストール ユーティリティが MyProjectInstaller にアクセスすると、InstallerCollection.Add の呼び出しを通じて Installers コレクションに追加されたオブジェクトが順番にインストールされます。このプロセス中に、インストーラは、どのオブジェクトがインストールされているのかを示す状態情報を保持します。このため、インストールに失敗した場合でも、それぞれのオブジェクトを順番に回復できます。
通常、プロジェクト インストーラ クラスは明示的にインスタンス化しません。プロジェクト インストーラ クラスを作成して、RunInstallerAttribute を追加しますが、実際にクラスを呼び出してインスタンス化するのはインストール ユーティリティです。
Imports System Imports System.Collections Imports System.Configuration.Install Imports System.ServiceProcess Imports System.ComponentModel <RunInstallerAttribute(True)> _ Public Class MyProjectInstaller Inherits Installer Private serviceInstaller1 As ServiceInstaller Private serviceInstaller2 As ServiceInstaller Private processInstaller As ServiceProcessInstaller Public Sub New() ' Instantiate installers for process and services. processInstaller = New ServiceProcessInstaller() serviceInstaller1 = New ServiceInstaller() serviceInstaller2 = New ServiceInstaller() ' The services will run under the system account. processInstaller.Account = ServiceAccount.LocalSystem ' The services will be started manually. serviceInstaller1.StartType = ServiceStartMode.Manual serviceInstaller2.StartType = ServiceStartMode.Manual ' ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.ServiceName = "Hello-World Service 1" serviceInstaller2.ServiceName = "Hello-World Service 2" ' Add installers to collection. Order is not important. Installers.Add(serviceInstaller1) Installers.Add(serviceInstaller2) Installers.Add(processInstaller) End Sub End Class
using System; using System.Collections; using System.Configuration.Install; using System.ServiceProcess; using System.ComponentModel; [RunInstallerAttribute(true)] public class MyProjectInstaller: Installer{ private ServiceInstaller serviceInstaller1; private ServiceInstaller serviceInstaller2; private ServiceProcessInstaller processInstaller; public MyProjectInstaller(){ // Instantiate installers for process and services. processInstaller = new ServiceProcessInstaller(); serviceInstaller1 = new ServiceInstaller(); serviceInstaller2 = new ServiceInstaller(); // The services run under the system account. processInstaller.Account = ServiceAccount.LocalSystem; // The services are started manually. serviceInstaller1.StartType = ServiceStartMode.Manual; serviceInstaller2.StartType = ServiceStartMode.Manual; // ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.ServiceName = "Hello-World Service 1"; serviceInstaller2.ServiceName = "Hello-World Service 2"; // Add installers to collection. Order is not important. Installers.Add(serviceInstaller1); Installers.Add(serviceInstaller2); Installers.Add(processInstaller); } }
#using <System.dll> #using <System.ServiceProcess.dll> #using <System.Configuration.Install.dll> using namespace System; using namespace System::Collections; using namespace System::Configuration::Install; using namespace System::ServiceProcess; using namespace System::ComponentModel; [RunInstallerAttribute(true)] public ref class MyProjectInstaller: public Installer { private: ServiceInstaller^ serviceInstaller1; ServiceInstaller^ serviceInstaller2; ServiceProcessInstaller^ processInstaller; public: MyProjectInstaller() { // Instantiate installers for process and services. processInstaller = gcnew ServiceProcessInstaller; serviceInstaller1 = gcnew ServiceInstaller; serviceInstaller2 = gcnew ServiceInstaller; // The services run under the system account. processInstaller->Account = ServiceAccount::LocalSystem; // The services are started manually. serviceInstaller1->StartType = ServiceStartMode::Manual; serviceInstaller2->StartType = ServiceStartMode::Manual; // ServiceName must equal those on ServiceBase derived classes. serviceInstaller1->ServiceName = "Hello-World Service 1"; serviceInstaller2->ServiceName = "Hello-World Service 2"; // Add installers to collection. Order is not important. Installers->Add( serviceInstaller1 ); Installers->Add( serviceInstaller2 ); Installers->Add( processInstaller ); } };
import System.*; import System.Collections.*; import System.Configuration.Install.*; import System.ServiceProcess.*; import System.ComponentModel.*; /** @attribute RunInstallerAttribute(true) */ public class MyProjectInstaller extends Installer { private ServiceInstaller serviceInstaller1; private ServiceInstaller serviceInstaller2; private ServiceProcessInstaller processInstaller; public MyProjectInstaller() { // Instantiate installers for process and services. processInstaller = new ServiceProcessInstaller(); serviceInstaller1 = new ServiceInstaller(); serviceInstaller2 = new ServiceInstaller(); // The services run under the system account. processInstaller.set_Account(ServiceAccount.LocalSystem); // The services are started manually. serviceInstaller1.set_StartType(ServiceStartMode.Manual); serviceInstaller2.set_StartType(ServiceStartMode.Manual); // ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.set_ServiceName("Hello-World Service 1"); serviceInstaller2.set_ServiceName("Hello-World Service 2"); // Add installers to collection. Order is not important. get_Installers().Add(serviceInstaller1); get_Installers().Add(serviceInstaller2); get_Installers().Add(processInstaller); } //MyProjectInstaller } //MyProjectInstaller

System.MarshalByRefObject
System.ComponentModel.Component
System.Configuration.Install.Installer
System.Configuration.Install.ComponentInstaller
System.ServiceProcess.ServiceProcessInstaller


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ServiceProcessInstaller クラスのページへのリンク