Unlike other types of .NET applications, you must explicitly install a Windows service application on the target system. Fortunately, VS.NET makes this task quite easy. For service projects, the IDE displays a link in the Properties window titled "Add Installer." When you click the link VS.NET adds the necessary installer classes to your project, as part of a separate module. You can set various properties, the most important of which is the Account
property of the ServiceProcessInstaller
class. The Account
property determines the security context under which the service will run.
The choices are:
- LocalService: The service has extensive local privileges and presents the computer's credentials to remote servers.
- LocalSystem: The service has limited local privileges and presents anonymous credentials to remote servers.
- NetworkService: The service has limited local privileges and presents the computer's credentials to remote servers.
- User: You specify a local or network account, and provide the username and password either as properties or during installation. The service uses the security context of the specified user account.
To install a service you must compile the service project into an exe
file, and then run the utility program InstallUtil.exe (installed with the .NET Framework). At a command prompt enter the command:
You must provide the complete path to the service's exe
file. The InstallUtil application installs the specified service. will be installed. After installing the new service, you can find it in the Services window of the Computer Management applet. (You can use the InstallUtil program to uninstall a service as well.)
Windows services are an often overlooked type of application. They are relatively specialized, but for certain type of tasks, usually in the administrative category, they fit the bill perfectly. The .NET Framework provides classes designed specifically for creating and controlling Windows service applications. Given that the required programming is relatively simple, you should take advantage of Windows services.