- Developing Windows Service on VB.NET, Part 1: Introduction
- Developing Windows Service on VB.NET, Part 2: Create Windows Service
- Developing Windows Service on VB.NET, Part 3: Create Setup Wizard
- Developing Windows Service on VB.NET, Part 4: Debug Service
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.
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.
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.
Log On As
There are 4 account types: User, LocalService, LocalSystem and NetworkService.
- 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.
- 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.
- LocalSystem, which runs in the context of an account that provides extensive local privileges, and presents the computer’s credentials to any remote server.
- 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.
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.
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.
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.