ServiceAccount Výčet

Definice

Určuje kontext zabezpečení služby, který definuje jeho typ přihlášení.

public enum class ServiceAccount
public enum ServiceAccount
type ServiceAccount = 
Public Enum ServiceAccount
Dědičnost
ServiceAccount

Pole

LocalService 0

Účet, který funguje jako neprivilegovaný uživatel v místním počítači, a představuje anonymní přihlašovací údaje pro jakýkoli vzdálený server.

LocalSystem 2

Účet používaný správcem řízení služeb, který má rozsáhlá oprávnění k místnímu počítači a funguje jako počítač v síti.

NetworkService 1

Účet, který poskytuje rozsáhlá místní oprávnění, a prezentuje přihlašovací údaje počítače na libovolném vzdáleném serveru.

User 3

Účet definovaný konkrétním uživatelem v síti. Zadání User člena Account způsobí, že systém při instalaci služby vyzve k zadání platného uživatelského jména a hesla, pokud nenastavíte hodnoty pro instanci Username i Password vlastnosti.ServiceProcessInstaller

Příklady

Následující příklad kódu ukazuje použití výčtu ServiceAccount k instalaci nových programů pomocí kontextu zabezpečení systémového účtu.

#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

Poznámky

Výčty ServiceAccount použijte při inicializaci ServiceProcessInstaller k určení kontextu zabezpečení služby, kterou instalujete. Kontext zabezpečení označuje oprávnění, která má služba v systému, a způsob, jakým služby fungují v síti (například jestli služba prezentuje přihlašovací údaje počítače nebo anonymní přihlašovací údaje vzdáleným serverům). Výčet ServiceAccount poskytuje rozsah oprávnění, abyste mohli přesně určit oprávnění, která potřebujete pro každou konkrétní službu.

Hodnota LocalSystem definuje vysoce privilegovaný účet, ale většina služeb nevyžaduje takovou úroveň zvýšených oprávnění. NetworkService Členové LocalService výčtu poskytují nižší úroveň oprávnění pro kontext zabezpečení.

Poznámka

Hodnoty LocalService a NetworkService jsou k dispozici pouze v řady Windows XP a Windows Server 2003.

Platí pro

Viz také