ServiceAccount 列挙型

定義

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

public enum class ServiceAccount
public enum ServiceAccount
type ServiceAccount = 
Public Enum ServiceAccount
継承
ServiceAccount

フィールド

LocalService 0

ローカル コンピューター上の特権を与えられていないユーザーとして機能するアカウント。このアカウントは、匿名の資格情報をリモート サーバーに提示します。

LocalSystem 2

ローカル コンピューター上で広範囲の特権を持ち、ネットワーク上のコンピューターとして機能するアカウント。このアカウントは、サービス コントロール マネージャーが使用します。

NetworkService 1

広範囲のローカル特権を提供するアカウント。このアカウントは、コンピューターの資格情報をリモート サーバーに提示します。

User 3

ネットワーク上の特定のユーザーによって定義されたアカウント。 Account メンバーに対して User を指定すると、Username インスタンスの Password プロパティ値と ServiceProcessInstaller プロパティ値を設定していない限りは、サービスのインストール時に有効なユーザー名とパスワードを入力するように要求されます。

次のコード例は、列挙体を使用して、システム アカウントの ServiceAccount セキュリティ コンテキストを使用して新しいプログラムをインストールする方法を示しています。

#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

注釈

初期化時に列挙体をServiceAccountServiceProcessInstaller使用して、インストールするサービスのセキュリティ コンテキストを指定します。 セキュリティ コンテキストは、サービスがシステムに対して持つ特権と、サービスがネットワーク上でどのように動作するかを示します (たとえば、サービスがコンピューターの資格情報または匿名資格情報をリモート サーバーに提示するかどうかなど)。 列挙は ServiceAccount 、特定のサービスに必要な特権を正確に指定できるように、さまざまな特権を提供します。

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

注意

LocalService``NetworkServiceは、Windows XP および Windows Server 2003 ファミリでのみ使用できます。

適用対象

こちらもご覧ください