15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating a Windows service Program ❘ 681<br />

}<br />

new System.ServiceProcess.ServiceInstaller();<br />

//<br />

// serviceProcessInstaller1<br />

//<br />

this.serviceProcessInstaller1.Password = null;<br />

this.serviceProcessInstaller1.Username = null;<br />

//<br />

// serviceInstaller1<br />

//<br />

this.serviceInstaller1.ServiceName = "QuoteService";<br />

//<br />

// ProjectInstaller<br />

//<br />

this.Installers.AddRange(<br />

new System.Configuration.Install.Installer[]<br />

{this.serviceProcessInstaller1,<br />

this.serviceInstaller1});<br />

private System.ServiceProcess.ServiceProcessInstaller<br />

serviceProcessInstaller1;<br />

private System.ServiceProcess.ServiceInstaller serviceInstaller1;<br />

}<br />

code snippet QuoteService/ProjectInstaller.Designer.cs<br />

ServiceProcessInstaller installs an executable that implements the class ServiceBase<br />

.ServiceProcessInstaller has properties for the complete process. The following table explains the<br />

properties shared by all the services inside the process.<br />

ProPerTy<br />

Username, Password<br />

Account<br />

HelpText<br />

desCriPTion<br />

Indicates the user account under which the service runs if the Account<br />

property is set to ServiceAccount.User.<br />

With this property, you can specify the account type of the service.<br />

HelpText is a read-only property that returns the help text for setting the<br />

username <strong>and</strong> password.<br />

The process that is used to run the service can be specified with the Account property of the<br />

ServiceProcessInstaller class using the ServiceAccount enumeration. The following table explains<br />

the different values of the Account property.<br />

Value<br />

LocalSystem<br />

NetworkService<br />

LocalService<br />

User<br />

meaning<br />

Setting this value specifies that the service uses a highly privileged user account on the<br />

local system, <strong>and</strong> acts as the computer on the network.<br />

Similarly to LocalSystem, this value specifies that the computer’s credentials are<br />

passed to remote servers, but unlike LocalSystem, such a service acts as a<br />

non-privileged user on the local system. As the name implies, this account should<br />

be used only for services that need resources from the network.<br />

This account type presents anonymous credentials to any remote server <strong>and</strong> has the<br />

same privileges locally as NetworkService.<br />

Setting the Account property to ServiceAccount.User means that you can define<br />

the account that should be used from the service.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!