次の方法で共有


ServiceAccount 列挙体

サービスのセキュリティ コンテキストを指定します。このコンテキストにより、そのサービスのログオンの種類が定義されます。

<Serializable>
Public Enum ServiceAccount
[C#]
[Serializable]
public enum ServiceAccount
[C++]
[Serializable]
__value public enum ServiceAccount
[JScript]
public
   Serializable
enum ServiceAccount

解説

ServiceProcessInstaller を初期化するときに ServiceAccount クラスを使用して、これからインストールするサービスのセキュリティ コンテキストを指定します。セキュリティ コンテキストは、システムにおいてサービスに与えられる特権と、ネットワーク上でのそのサービスの動作 (たとえば、サービスがコンピュータの資格情報または匿名の資格情報をリモート サーバーに提示するかどうか) を示します。 ServiceAccount クラスは、特定のサービスに必要な特権を正確に指定できるように、一定範囲に含まれる複数の特権をまとめて提供します。

LocalSystem 値は、高レベルの特権を与えられたアカウントを定義しますが、ほとんどのサービスにはそれほど高い特権レベルは必要ありません。 LocalService 列挙体メンバと NetworkService 列挙体メンバは、セキュリティ コンテキストに対して、それよりも低い特権レベルを提供します。

メモ    LocalService 値および NetworkService 値は Windows XP でだけ使用できます。

メンバ

メンバ名 説明
LocalService ローカル コンピュータ上の特権を与えられていないユーザーとして機能するアカウント。このアカウントは、匿名の資格情報をリモート サーバーに提示します。
LocalSystem 高い特権レベルを持つアカウント。
NetworkService 広範囲のローカル特権を提供するアカウント。このアカウントは、コンピュータの資格情報をリモート サーバーに提示します。
User ネットワーク上の特定のユーザーによって定義されたアカウント。 ServiceProcessInstaller.Account メンバに対して User を指定すると、 ServiceProcessInstaller インスタンスの Username プロパティ値と Password プロパティ値を設定していない限りは、サービスのインストール時に有効なユーザー名とパスワードを入力するように要求されます。

使用例

 
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 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Serviceprocess (System.Serviceprocess.dll 内)

参照

System.ServiceProcess 名前空間 | ServiceProcessInstaller