Developing Windows Service on VB.NET, Part 1: Introduction

This entry is part 1 of 4 in the series Developing Windows Service on VB.NET

Introduction to Windows Service

What is Windows service? Windows Service is an application or a program that can run without needing any user interaction. It is useful in server environment that no need user to logged in on the system but the services are running. The status message of the service always write to event log.

Startup type

Windows service runs in the background when Windows is started if its startup type is automatic. If the startup type is manual, the service will not start when Windows boots. It’ll need user or other Windows service to start it. To observe running service on the system, you can view in processes on Windows Task Manager. To open Windows Task Manager, hold Ctrl+Alt+Delete and select Task Manager. Most of the processes that run with user name SYSTEM are services but not all of the processes is a Windows service. The example of process list is the figure below. You can see some highlights which are well known services such as Apache (httpd.exe), MySQL (mysqld-nt.exe), IIS (inetinfo.exe) and Acronis’s agent(agent.exe). There are more processes which are services but I’ll not mentioned here.
Processes on Windows Task Manager

To manage Windows services, open Start -> Run -> type ‘services.msc’. You’ll see that some services are started, some are not. You can right click on the service and select to start, stop, pause and restart service manually.
Introduction to Windows Service - Windows Services

Log On As

Also, you can change the ‘Log On As’ to different user account by right click on the service and select Properties. Select Log on tab to change user for running this service.
Change user to run the service

There are 4 account types: User, LocalService, LocalSystem and NetworkService.

  1. User, which causes the system to prompt for a valid user name and password when the service is installed and runs in the context of an account specified by a single user on the network.
  2. LocalService, which runs in the context of an account that acts as a non-privileged user on the local computer, and presents anonymous credentials to any remote server.
  3. LocalSystem, which runs in the context of an account that provides extensive local privileges, and presents the computer’s credentials to any remote server.
  4. NetworkService, which runs in the context of an account that acts as a non-privileged user on the local computer, and presents the computer’s credentials to any remote server.

Recovery

In some case, the service can’t be started because it may be error. You can define recovery action whether to take no action (do nothing), restart the service, run a program and restart the service on ‘Recovery’ tab.
Recovery service

Dependencies

A service may depends on the other services so when you start this service, you need to start the dependent service before. You can view the dependencies service on ‘Dependencies’ tab. It’ll show service that this service depends on and services that depend on this service. In the figure below is the apache service. It is depends on AFD Networking Support Environment and TCP/IP Protocol Driver which are system components not services. For service, the icon must look like 2 gears.
View service's dependencies

Windows service can be develop easily by using Microsoft Visual Studio 2005. In the next part, I’ll show how to develop a very simple service that generate a message to eventlog every 10 seconds with installer on MS Visual Studio 2005.

Series NavigationDeveloping Windows Service on VB.NET, Part 2: Create Windows Service >>

One Response

  1. mihir shah December 2, 2013

Leave a Reply