3. WHAT IS WINDOWS SERVICES?
Windows Services
• A.K.A NT Services
• long-running executable applications that run
in their own Windows sessions
• Runs on background (no UI)
• Example services: DB Server, Anti-virus,
SSH, HTTP, Printer Spooler, etc
• Configurable:
• Runs on startup (computer boot)
• Delay run
• Manual / Auto run
• Start with parameter
• Starts for specific username
• An application can be programmable to run
as a services via .NET (creating a Windows
Service Application)
9. • Started
• Pause
• Pending
• Stop
Service
Status
• Automatic
• Manual
• Delay Start
• Disabled
Service
Start Mode
• Local System
• Local Service
• Network Service
Start As/By
More info:
1. https://technet.microsoft.com/en-us/library/cc755249.aspx
2. http://www.howtogeek.com/school/using-windows-admin-tools-like-a-pro/lesson8/
UNDERSTANDING WINDOWS SERVICES
10. Parameter that
can be changed
SQL Servers start parameter eg:
-e [error log path] –g [memory to
reserve]
will set error log location and starting
memory to be used
UNDERSTANDING WINDOWS SERVICES
11. Control access to the services
Applicable for hardware
based services
UNDERSTANDING WINDOWS SERVICES
12. Determine the action if the services failed
If three consecutives
startup failed, the services
can trigger to run a program
such as send notifications,
log error, etc.
UNDERSTANDING WINDOWS SERVICES
13. The services/component that the
service dependent on
The component/services that has
dependencies to the service
UNDERSTANDING WINDOWS SERVICES
14. Getting response
via command
prompt
C:Usershaszeli>sc queryex MSSQL$SQLEXPRESS
SERVICE_NAME: MSSQL$SQLEXPRESS
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 0
FLAGS :
C:Usershaszeli>
* You can also use net command to perform start/stop/pause/continue a service.
UNDERSTANDING WINDOWS SERVICES
15. • Not all services it shall runs
• Depends on the usage of the PC / Server
Configuring Services - that you should start / disabled
1. Windows 8.1 - http://www.blackviper.com/service-configurations/black-vipers-
windows-8-1-service-configurations/
2. Windows 7 - http://www.blackviper.com/service-configurations/black-vipers-
windows-7-service-pack-1-service-configurations/
3. Windows Vista - http://www.blackviper.com/service-configurations/black-vipers-
windows-vista-service-pack-2-service-configurations/
4. Windows XP - http://www.blackviper.com/service-configurations/black-vipers-
windows-xp-x86-32-bit-service-pack-3-service-configurations/
Others: http://www.blackviper.com/service-configurations/
UNDERSTANDING WINDOWS SERVICES
16. PROGRAMMING WINDOWS SERVICES
Requirement:
Visual Studio (IDE)
.NET Framework
Programming skill – VB.NET and C#
List of possible function calls
https://msdn.microsoft.com/en-
us/library/System.ServiceProcess(v=vs.110).aspx
• Creating Windows Services
1. Create .NET Windows Services Project
https://msdn.microsoft.com/en-us/library/9k985bc9(v=vs.110).aspx
2. Write the program
https://msdn.microsoft.com/en-us/library/76477d2t(v=vs.110).aspx
3. Code the services
https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
17. CREATING WINDOWS SERVICES
Creating services using Sc.exe command
https://support.microsoft.com/en-us/kb/251192
https://technet.microsoft.com/en-us/library/cc990289.aspx
Install and uninstall windows services program created using .NET
https://msdn.microsoft.com/en-us/library/sd8zc8ha(v=vs.110).aspx
http://stackoverflow.com/questions/8164859/install-a-windows-
service-using-a-windows-command-prompt
https://coderamblings.wordpress.com/2012/07/24/how-to-install-a-
windows-service-using-the-command-prompt/
18. WINDOWS SERVICES
VS
TASK SCHEDULER
Windows Services Task Scheduler
Running a permanent or continuous
operation/task
Running a program/apps once a while
(on frequency basis)
When a service is required to provide
data/operation when
needed/triggered
Running at its own pace. Process and
provide output but does not dependent
on other program/input
Complex program and/or application
that is very complex in coding and
processing
Simple operation or program that can
be easily managed
Triggered via events or programs Triggered via time
Process Explorer – Much more better – Shows services and its dependencies
Process Explorer – Much more better – Shows services and its dependencies
Process Explorer – Much more better – Shows services and its dependencies
Process Explorer – Much more better – Shows services and its dependencies
Local System – based on user profile
Local Service – Control by user with administrator right / Created by Application/OS
Network Service – Control by IT Administrator
Using system utility: sc command.
Another way is to use net command
Eg:
C:\Users\haszeli>net start MSSQL$SQLEXPRESS
The SQL Server (SQLEXPRESS) service is starting....
The SQL Server (SQLEXPRESS) service was started successfully.
C:\Users\haszeli>net stop MSSQL$SQLEXPRESS
The SQL Server (SQLEXPRESS) service is stopping.
The SQL Server (SQLEXPRESS) service was stopped successfully.