ServiceBase を拡張するクラスを含む実行可能ファイルをインストールします。このクラスは、サービス アプリケーションのインストール時に InstallUtil.exe などのインストール ユーティリティで呼び出されます。
この型のすべてのメンバの一覧については、ServiceProcessInstaller メンバ を参照してください。
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Configuration.Install.Installer
System.Configuration.Install.ComponentInstaller
System.ServiceProcess.ServiceProcessInstaller
Public Class ServiceProcessInstaller
Inherits ComponentInstaller
[C#]
public class ServiceProcessInstaller : ComponentInstaller
[C++]
public __gc class ServiceProcessInstaller : public
ComponentInstaller
[JScript]
public class ServiceProcessInstaller extends ComponentInstaller
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
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 が呼び出されます。
使用例
[Visual Basic, C#, C++] Installer から継承される、MyProjectInstaller という名前のプロジェクト インストーラを作成する例を次に示します。この例では、2 つのサービス "Hello-World Service 1" および "Hello-World Service 2" を含んだ、サービスの実行可能ファイルがあることを前提にしています。インストール ユーティリティによって呼び出される MyProjectInstaller のコンストラクタ内では、これらの各サービスに対して ServiceInstaller オブジェクトが作成され、実行可能ファイルに対して ServiceProcessInstaller が作成されます。インストール ユーティリティで MyProjectInstaller を有効なインストーラとして認識できるように、RunInstallerAttribute 属性は true に設定されます。
[Visual Basic, C#, C++] インストーラが Installers コレクションに追加される前に、オプションのプロパティがプロセス インストーラおよびサービス インストーラに設定されます。インストール ユーティリティが MyProjectInstaller にアクセスすると、 InstallerCollection.Add の呼び出しを通じて Installers コレクションに追加されたオブジェクトが順番にインストールされます。このプロセス中に、インストーラは、どのオブジェクトがインストールされているのかを示す状態情報を保持します。このため、インストールに失敗した場合でも、それぞれのオブジェクトを順番に回復できます。
[Visual Basic, C#, C++] 通常、プロジェクト インストーラ クラスは明示的にインスタンス化しません。プロジェクト インストーラ クラスを作成して、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
' </Sn
[C#]
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);
}
}
[C++]
#using <mscorlib.dll>
#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 __gc class MyProjectInstaller: public Installer{
private:
ServiceInstaller* serviceInstaller1;
ServiceInstaller* serviceInstaller2;
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 = S"Hello-World Service 1";
serviceInstaller2->ServiceName = S"Hello-World Service 2";
// Add installers to collection. Order is not important.
Installers->Add(serviceInstaller1);
Installers->Add(serviceInstaller2);
Installers->Add(processInstaller);
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.ServiceProcess
プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Serviceprocess (System.Serviceprocess.dll 内)
参照
ServiceProcessInstaller メンバ | System.ServiceProcess 名前空間 | ServiceInstaller | ServiceBase | ComponentInstaller | Installers | ServiceAccount