ServiceAccount Enumerazione

Definizione

Specifica un contesto di sicurezza di un servizio, con cui viene definito il tipo di accesso.

public enum class ServiceAccount
public enum ServiceAccount
type ServiceAccount = 
Public Enum ServiceAccount
Ereditarietà
ServiceAccount

Campi

LocalService 0

Account con cui si agisce come utente senza privilegi sul computer locale e si presentano credenziali anonime a qualsiasi server remoto.

LocalSystem 2

Account, utilizzato dalla Gestione controllo servizi, che dispone di privilegi estesi al computer locale e funziona come computer in rete.

NetworkService 1

Account con cui vengono forniti privilegi locali estesi e presentate le credenziali del computer a qualsiasi server remoto.

User 3

Account definito da un utente specifico sulla rete. Se si specifica User per il membro Account, quando il servizio viene installato, il sistema richiede una password e un nome utente validi, a meno che non vengano impostati i valori per entrambe le proprietà Username e Password dell'istanza ServiceProcessInstaller.

Esempio

Nell'esempio di codice seguente viene illustrato come usare l'enumerazione ServiceAccount per installare nuovi programmi usando il contesto di sicurezza dell'account di sistema.

#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

Commenti

Usare l'enumerazione ServiceAccount quando si inizializza un ServiceProcessInstaller per specificare il contesto di sicurezza del servizio che si installa. Il contesto di sicurezza indica i privilegi di un servizio nel sistema e il modo in cui i servizi agiscono sulla rete ( ad esempio, se il servizio presenta le credenziali del computer o le credenziali anonime ai server remoti). L'enumerazione ServiceAccount fornisce un intervallo di privilegi in modo da poter specificare esattamente i privilegi necessari per qualsiasi servizio specifico.

Il LocalSystem valore definisce un account con privilegi elevati, ma la maggior parte dei servizi non richiede tale livello di privilegi elevati. I LocalService membri dell'enumerazione NetworkService forniscono un livello di privilegio inferiore per il contesto di sicurezza.

Nota

I valori LocalService e NetworkService sono disponibili solo nella famiglia Windows XP e Windows Server 2003.

Si applica a

Vedi anche