Export (0) Print
Expand All

ServiceAccount Enumeration

Specifies a service's security context, which defines its logon type.

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

Remarks

Use the ServiceAccount class when you initialize a ServiceProcessInstaller to specify the security context of the service you are installing. The security context indicates the privileges a service has on the system and how the services acts on the network (for example, whether the service presents the computer's credentials or anonymous credentials to remote servers). The ServiceAccount class provides a range of privileges so that you can specify exactly the privileges you need for any particular service.

The LocalSystem value defines a highly privileged account, but most services do not require such an elevated privilege level. The LocalService and NetworkService enumeration members provide a lower privilege level for the security context.

Note   The values LocalService and NetworkService are available only on Windows XP.

Members

Member name Description
LocalService An account that acts as a non-privileged user on the local computer, and presents anonymous credentials to any remote server.
LocalSystem An account that has a high privileged level.
NetworkService An account that provides extensive local privileges, and presents the computer's credentials to any remote server.
User An account defined by a specific user on the network. Specifying User for the ServiceProcessInstaller.Account member causes the system to prompt for a valid user name and password when the service is installed, unless you set values for both the Username and Password properties of your ServiceProcessInstaller instance.

Example

[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ServiceProcess

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Serviceprocess (in System.Serviceprocess.dll)

See Also

System.ServiceProcess Namespace | ServiceProcessInstaller

Show:
© 2014 Microsoft