Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

ServiceAccount Enumeration

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

Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)

public enum ServiceAccount
public enum ServiceAccount
public enum ServiceAccount
 Member nameDescription
LocalServiceAn account that acts as a non-privileged user on the local computer, and presents anonymous credentials to any remote server. 
LocalSystemAn account, used by the service control manager, that has extensive privileges on the local computer and acts as the computer on the network. 
NetworkServiceAn account that provides extensive local privileges, and presents the computer's credentials to any remote server. 
UserAn 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. 

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.

NoteNote

The values LocalService and NetworkService are available only on Windows XP and Windows Server 2003 family.

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);
   }
}


import System.*;
import System.Collections.*;
import System.Configuration.Install.*;
import System.ServiceProcess.*;
import System.ComponentModel.*;

/** @attribute RunInstallerAttribute(true)
 */
public class MyProjectInstaller extends 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.set_Account(ServiceAccount.LocalSystem);

        // The services are started manually.
        serviceInstaller1.set_StartType(ServiceStartMode.Manual);
        serviceInstaller2.set_StartType(ServiceStartMode.Manual);

        // ServiceName must equal those on ServiceBase derived classes.            
        serviceInstaller1.set_ServiceName("Hello-World Service 1");
        serviceInstaller2.set_ServiceName("Hello-World Service 2");

        // Add installers to collection. Order is not important.
        get_Installers().Add(serviceInstaller1);
        get_Installers().Add(serviceInstaller2);
        get_Installers().Add(processInstaller);
    } //MyProjectInstaller
} //MyProjectInstaller

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.