Bahasa

ServiceAccount Enum

Definisi

Menentukan konteks keamanan layanan, yang menentukan jenis masuknya.

public enum class ServiceAccount
public enum ServiceAccount
type ServiceAccount = 
Public Enum ServiceAccount
Warisan
ServiceAccount

Bidang

Nama Nilai Deskripsi
LocalService 0

Akun yang bertindak sebagai pengguna non-istimewa di komputer lokal, dan menyajikan kredensial anonim ke server jarak jauh apa pun.

NetworkService 1

Akun yang menyediakan hak istimewa lokal yang luas, dan menyajikan kredensial komputer ke server jarak jauh mana pun.

LocalSystem 2

Akun, yang digunakan oleh manajer kontrol layanan, yang memiliki hak istimewa yang luas di komputer lokal dan bertindak sebagai komputer di jaringan.

User 3

Akun yang ditentukan oleh pengguna tertentu di jaringan. Menentukan User anggota Account menyebabkan sistem meminta nama pengguna dan kata sandi yang valid saat layanan diinstal, kecuali Anda menetapkan nilai untuk Username properti dan Password instans Anda ServiceProcessInstaller .

Contoh

Contoh kode berikut menunjukkan cara menggunakan ServiceAccount enumerasi untuk menginstal program baru dengan menggunakan konteks keamanan akun sistem.

#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

Keterangan

ServiceAccount Gunakan enumerasi saat Anda menginisialisasi ServiceProcessInstaller untuk menentukan konteks keamanan layanan yang Anda instal. Konteks keamanan menunjukkan hak istimewa yang dimiliki layanan pada sistem dan bagaimana layanan bertindak pada jaringan (misalnya, apakah layanan menyajikan kredensial komputer atau kredensial anonim ke server jarak jauh). Enumerasi ServiceAccount memberikan berbagai hak istimewa sehingga Anda dapat menentukan hak istimewa yang Anda butuhkan untuk layanan tertentu.

Nilai LocalSystem mendefinisikan akun yang sangat istimewa, tetapi sebagian besar layanan tidak memerlukan tingkat hak istimewa yang ditinggikan seperti itu. Anggota LocalService enumerasi dan NetworkService memberikan tingkat hak istimewa yang lebih rendah untuk konteks keamanan.

Note

Nilai LocalService dan NetworkService hanya tersedia pada keluarga Windows XP dan Windows Server 2003.

Berlaku untuk

Lihat juga