ServiceProcessInstaller クラス

定義

ServiceBaseを拡張するクラスを含む実行可能ファイルをインストールします。 このクラスは、サービス アプリケーションをインストールするときに、InstallUtil.exeなどのインストール ユーティリティによって呼び出されます。

public ref class ServiceProcessInstaller : System::Configuration::Install::ComponentInstaller
public class ServiceProcessInstaller : System.Configuration.Install.ComponentInstaller
type ServiceProcessInstaller = class
    inherit ComponentInstaller
Public Class ServiceProcessInstaller
Inherits ComponentInstaller
継承

次の例では、 Installerから継承する MyProjectInstaller という名前のプロジェクト インストーラーを作成します。 "Hello-World Service 1" と "Hello-World Service 2" の 2 つのサービスを含むサービス実行可能ファイルがあることを前提としています。 MyProjectInstaller (インストール ユーティリティによって呼び出される) のコンストラクター内で、 ServiceInstaller オブジェクトがサービスごとに作成され、実行可能ファイルに対して ServiceProcessInstaller が作成されます。 インストール ユーティリティが MyProjectInstaller を有効なインストーラーとして認識するには、 RunInstallerAttribute 属性が true に設定されます。

オプションのプロパティは、インストーラーが Installers コレクションに追加される前に、プロセス インストーラーとサービス インストーラーで設定されます。 インストール ユーティリティが MyProjectInstaller にアクセスすると、InstallerCollection.Addの呼び出しによって Installers コレクションに追加されたオブジェクトが順番にインストールされます。 このプロセス中、インストーラーは、インストールされているオブジェクトを示す状態情報を保持するため、インストールエラーが発生した場合に各オブジェクトを順番にバックアウトできます。

通常は、プロジェクト インストーラー クラスを明示的にインスタンス化しません。 これを作成して RunInstallerAttributeを追加しますが、インストール ユーティリティは実際にクラスを呼び出してインスタンス化します。

#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;

[RunInstaller(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 );
    }

    static void Main()
    {
        Console::WriteLine("Usage: InstallUtil.exe [<service>.exe]");
    }
};

int main()
{
    MyProjectInstaller::Main();
}
using System;
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;

[RunInstaller(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);
    }

    public static void Main()
    {
        Console.WriteLine("Usage: InstallUtil.exe [<service>.exe]");
    }
}
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

    Public Shared Sub Main()
        Console.WriteLine("Usage: InstallUtil.exe [<service>.exe]")
    End Sub
End Class

注釈

ServiceProcessInstallerは、実行可能ファイル内のすべてのサービスに共通して機能します。 インストール ユーティリティは、インストールするサービスに関連付けられているレジストリ値を書き込む目的で使用されます。

サービスをインストールするには、 Installerから継承するプロジェクト インストーラー クラスを作成し、クラスの RunInstallerAttributetrue に設定します。 プロジェクト内で、サービス アプリケーションごとに 1 つの ServiceProcessInstaller インスタンスと、アプリケーション内のサービスごとに 1 つの ServiceInstaller インスタンスをインスタンス化します。 最後に、 ServiceProcessInstaller インスタンスと ServiceInstaller インスタンスをプロジェクト インストーラー クラスに追加します。

InstallUtil.exe 実行すると、 RunInstallerAttributetrue に設定されたサービス アセンブリ内のクラスが検索されます。 プロジェクト インストーラーに関連付けられている Installers コレクションにクラスを追加して、サービス アセンブリにクラスを追加します。 RunInstallerAttributefalseされている場合、インストール ユーティリティはプロジェクト インストーラーを無視します。

ServiceProcessInstallerのインスタンスの場合、変更できるプロパティには、ログオンしているユーザー以外のアカウントでサービス アプリケーションを実行することを指定するプロパティが含まれます。 サービスを実行する特定の UsernamePassword のペアを指定することも、 Account を使用して、コンピューターのシステム アカウント、ローカルまたはネットワーク サービス アカウント、またはユーザー アカウントでサービスを実行するように指定することもできます。

Note

コンピューターのシステム アカウントが管理者アカウントと同じではありません。

通常、コード内の ServiceInstaller でメソッドを呼び出すわけではありません。通常、これらはインストール ユーティリティによってのみ呼び出されます。 インストール ユーティリティは、インストール プロセス中に ServiceProcessInstaller.Install メソッドと ServiceInstaller.Install メソッドを自動的に呼び出します。 以前にインストールされたすべてのコンポーネントで Rollback (または ServiceInstaller.Rollback) を呼び出すことで、必要に応じてエラーをバックアウトします。

アプリケーションのインストール ルーチンは、プロジェクト インストーラーの Installer.Contextを使用して、既にインストールされているコンポーネントに関する情報を自動的に保持します。 この状態情報は、 ServiceProcessInstaller インスタンスとして継続的に更新され、各 ServiceInstaller インスタンスがユーティリティによってインストールされます。 通常、コードでこの状態情報を明示的に変更する必要があります。

ServiceProcessInstallerをインスタンス化すると、基底クラスコンストラクター (ComponentInstaller) が呼び出されます。

コンストラクター

名前 説明
ServiceProcessInstaller()

ServiceProcessInstaller クラスの新しいインスタンスを作成します。

プロパティ

名前 説明
Account

このサービス アプリケーションを実行するアカウントの種類を取得または設定します。

CanRaiseEvents

コンポーネントがイベントを発生できるかどうかを示す値を取得します。

(継承元 Component)
Container

IContainerを含むComponentを取得します。

(継承元 Component)
Context

現在のインストールに関する情報を取得または設定します。

(継承元 Installer)
DesignMode

Componentが現在デザイン モードであるかどうかを示す値を取得します。

(継承元 Component)
Events

この Componentにアタッチされているイベント ハンドラーの一覧を取得します。

(継承元 Component)
HelpText

サービスのインストール オプションに表示されるヘルプ テキストを取得します。

Installers

このインストーラーに含まれるインストーラーのコレクションを取得します。

(継承元 Installer)
Parent

このインストーラーが属するコレクションを含むインストーラーを取得または設定します。

(継承元 Installer)
Password

サービス アプリケーションを実行するユーザー アカウントに関連付けられているパスワードを取得または設定します。

Site

ISiteComponentを取得または設定します。

(継承元 Component)
Username

サービス アプリケーションを実行するユーザー アカウントを取得または設定します。

メソッド

名前 説明
Commit(IDictionary)

派生クラスでオーバーライドされると、インストール トランザクションが完了します。

(継承元 Installer)
CopyFromComponent(IComponent)

基底クラス CopyFromComponent(IComponent) メソッドを実装し、クラス固有の動作 ServiceProcessInstaller しません。

CreateObjRef(Type)

リモート オブジェクトとの通信に使用されるプロキシの生成に必要なすべての関連情報を含むオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

Componentによって使用されるすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)

Componentによって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。

(継承元 Component)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()

このインスタンスの有効期間ポリシーを制御する現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetService(Type)

ComponentまたはそのContainerによって提供されるサービスを表すオブジェクトを返します。

(継承元 Component)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
Install(IDictionary)

サービス アプリケーション情報をレジストリに書き込みます。 このメソッドは、適切なメソッドを自動的に呼び出すインストール ツールで使用するためのものです。

IsEquivalentInstaller(ComponentInstaller)

指定したインストーラーがこのインストーラーと同じオブジェクトをインストールするかどうかを判断します。

(継承元 ComponentInstaller)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
OnAfterInstall(IDictionary)

AfterInstall イベントを発生させます。

(継承元 Installer)
OnAfterRollback(IDictionary)

AfterRollback イベントを発生させます。

(継承元 Installer)
OnAfterUninstall(IDictionary)

AfterUninstall イベントを発生させます。

(継承元 Installer)
OnBeforeInstall(IDictionary)

BeforeInstall イベントを発生させます。

(継承元 Installer)
OnBeforeRollback(IDictionary)

BeforeRollback イベントを発生させます。

(継承元 Installer)
OnBeforeUninstall(IDictionary)

BeforeUninstall イベントを発生させます。

(継承元 Installer)
OnCommitted(IDictionary)

Committed イベントを発生させます。

(継承元 Installer)
OnCommitting(IDictionary)

Committing イベントを発生させます。

(継承元 Installer)
Rollback(IDictionary)

インストール手順によってレジストリに書き込まれたサービス アプリケーション情報をロールバックします。 この方法は、適切な方法を自動的に処理するインストール ツールで使用することを目的としています。

ToString()

Stringの名前 (存在する場合) を含むComponentを返します。 このメソッドはオーバーライドしないでください。

(継承元 Component)
Uninstall(IDictionary)

派生クラスでオーバーライドされた場合は、インストールを削除します。

(継承元 Installer)

イベント

名前 説明
AfterInstall

Install(IDictionary) プロパティ内のすべてのインストーラーのInstallers メソッドが実行された後に発生します。

(継承元 Installer)
AfterRollback

Installers プロパティ内のすべてのインストーラーのインストールがロールバックされた後に発生します。

(継承元 Installer)
AfterUninstall

Installers プロパティ内のすべてのインストーラーがアンインストール操作を実行した後に発生します。

(継承元 Installer)
BeforeInstall

インストーラー コレクション内の各インストーラーの Install(IDictionary) メソッドが実行される前に発生します。

(継承元 Installer)
BeforeRollback

Installers プロパティのインストーラーがロールバックされる前に発生します。

(継承元 Installer)
BeforeUninstall

Installers プロパティのインストーラーがアンインストール操作を実行する前に発生します。

(継承元 Installer)
Committed

Installers プロパティ内のすべてのインストーラーがインストールをコミットした後に発生します。

(継承元 Installer)
Committing

Installers プロパティのインストーラーがインストールをコミットする前に発生します。

(継承元 Installer)
Disposed

コンポーネントが Dispose() メソッドの呼び出しによって破棄されるときに発生します。

(継承元 Component)

適用対象

こちらもご覧ください