Download presentation
Presentation is loading. Please wait.
Published byLorraine Wright Modified over 9 years ago
1
WINDOWS SERVICES
2
Introduction You often need programs that run continuously in the background Examples: –Email servers –Print spooler You often need programs that run continuously in the background Examples: –Email servers –Print spooler
3
Operating Systems Provisions UNIX: Daemons Windows NT: NT Services Windows 2000, Windows XP, Windows Server 2003: Windows services UNIX: Daemons Windows NT: NT Services Windows 2000, Windows XP, Windows Server 2003: Windows services
4
Facilities For Integrating Products With Windows OS The Windows operating system provides a set of services that allow device manufacturers and software vendors to integrate their products with the operating system.
5
Requirements of Windows Services Created as normal executable files Must conform to the interface of the Services Control Manager (SCM), which manages Windows services Must be installed in the Windows services database before use Created as normal executable files Must conform to the interface of the Services Control Manager (SCM), which manages Windows services Must be installed in the Windows services database before use
6
Skills Needed Create a Windows service that conforms to SCM interface Create an installer class that is capable of installing a Windows service to the Windows service database Create a Windows service that conforms to SCM interface Create an installer class that is capable of installing a Windows service to the Windows service database
7
Skills Needed (cont’d) Use the Installer tool (installutil.exe) to install and uninstall a Windows service to the Windows service database Connect to a Windows service and issue messages such as start, stop, and continue Query a Windows service to retrieve its status Use the Installer tool (installutil.exe) to install and uninstall a Windows service to the Windows service database Connect to a Windows service and issue messages such as start, stop, and continue Query a Windows service to retrieve its status
8
Facilities (cont’d) Kernel Services –Core part of operating system responsible for process, thread, and memory management –Enables devices and application to interact with the kernel and use its functionality –Used by systems programmers Kernel Services –Core part of operating system responsible for process, thread, and memory management –Enables devices and application to interact with the kernel and use its functionality –Used by systems programmers
9
Facilities (cont’d) Device Driver Services –A device driver controls and manages a specific type of hardware device –Device driver services enable applications to work with devices –Used by systems programmers Device Driver Services –A device driver controls and manages a specific type of hardware device –Device driver services enable applications to work with devices –Used by systems programmers
10
Facilities (cont’d) Windows Services –Enables operating system components and application programs to expose their functionality to other applications –Applications programmers use this service Windows Services –Enables operating system components and application programs to expose their functionality to other applications –Applications programmers use this service
11
Characteristics of Windows Services Conformance to SCM –Must implement a set of well-known methods, which enable the service to communicate with the SCM –E.g.: Stop, Start, Continue, Pause –Not all Windows services handle all messages Conformance to SCM –Must implement a set of well-known methods, which enable the service to communicate with the SCM –E.g.: Stop, Start, Continue, Pause –Not all Windows services handle all messages
12
Characteristics of Windows Services (cont’d) Examples: –Event Log and Plug and Play do not accept Pause and Stop messages –Print Spooler accepts Start and Stop, but not Pause Examples: –Event Log and Plug and Play do not accept Pause and Stop messages –Print Spooler accepts Start and Stop, but not Pause
13
Characteristics of Windows Services (cont’d) Lack of User Interface –Can have user interface, but most do not –They perform system tasks that usually do not require user interface –Example: IIS Launched when OS is booted up Is unseen by user, doesn’t require interface Lack of User Interface –Can have user interface, but most do not –They perform system tasks that usually do not require user interface –Example: IIS Launched when OS is booted up Is unseen by user, doesn’t require interface
14
Characteristics of Windows Services (cont’d) Long-lived Process –Typically, is started automatically and continues to live –Can execute even when no user is logged on Long-lived Process –Typically, is started automatically and continues to live –Can execute even when no user is logged on
15
Characteristics of Windows Services (cont’d) Specific User Identity –Most run with System privileges –System is a special account that Windows uses to perform privileged operations –A service can be launched with a specific user identity, which can be used to restrict permissions Specific User Identity –Most run with System privileges –System is a special account that Windows uses to perform privileged operations –A service can be launched with a specific user identity, which can be used to restrict permissions
16
Characteristics of Windows Services (cont’d) Specific User Identity (cont’d) –System administrator can accomplish this easily: 1. Set up a user account with the permissions that the administrator wants the service to have 2. Configure the Windows service to run with the user identity that was created in Step 1 Specific User Identity (cont’d) –System administrator can accomplish this easily: 1. Set up a user account with the permissions that the administrator wants the service to have 2. Configure the Windows service to run with the user identity that was created in Step 1
17
Characteristics of Windows Services (cont’d) Separate Windows Process –A Windows service does not run in the process of the program that communicates with it –Runs in its own process –Can also share a process with another Windows service Separate Windows Process –A Windows service does not run in the process of the program that communicates with it –Runs in its own process –Can also share a process with another Windows service
18
Characteristics of Windows Services (cont’d) Special Installation Procedure –Cannot be started by just executing the *.exe file –Must be registered with the SCM Special Installation Procedure –Cannot be started by just executing the *.exe file –Must be registered with the SCM
19
Architecture of Windows Services Windows Service Database Service Control Manager Windows Service Installer Windows Services in execution Windows Service Controller Windows Service Database Service Control Manager Windows Service Installer Windows Services in execution Windows Service Controller
20
Windows Service Database Located in Registry at –HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\Services Each service contains following info: - Path to the executable file - Security settings - Startup parameters Located in Registry at –HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\Services Each service contains following info: - Path to the executable file - Security settings - Startup parameters
21
Windows Service Database (cont’d) Even though you can directly manipulate the Windows service database by modifying the Windows Registry using regedit, it is recommended that you do not To ensure integrity of the Registry, use the interface provided by SCM Even though you can directly manipulate the Windows service database by modifying the Windows Registry using regedit, it is recommended that you do not To ensure integrity of the Registry, use the interface provided by SCM
22
Service Control Manager (SCM) A Windows component that maintains the Windows service database Provides a unified way to control, configure and access these services A Windows component that maintains the Windows service database Provides a unified way to control, configure and access these services
23
Service Control Manager (SCM) (cont’d) Tasks performed: –Accepts requests to install and uninstall Windows services from the database –Starts Windows services either on system startup or on demand –Enumerates installed Windows services –Maintains status information for running services –Transmits control messages to running services –Locks and unlocks the Windows service database Tasks performed: –Accepts requests to install and uninstall Windows services from the database –Starts Windows services either on system startup or on demand –Enumerates installed Windows services –Maintains status information for running services –Transmits control messages to running services –Locks and unlocks the Windows service database
24
Windows Service Installer Uses the SCM to install, uninstall and repair a Windows service These actions create, delete, and update a Windows service record in the database Stores information about how a service will be started Uses the SCM to install, uninstall and repair a Windows service These actions create, delete, and update a Windows service record in the database Stores information about how a service will be started
25
Windows Service Installer (cont’d) Information that is stored: –Name that uniquely identifies service –Account name and password under whose identity the service runs –Independent or shared process –How service is started Information that is stored: –Name that uniquely identifies service –Account name and password under whose identity the service runs –Independent or shared process –How service is started
26
Windows Services in Execution SCM creates a process for a service based on information stored in the Windows service database SCM sends a Start message to the service After a Windows service is started, it continues to run until it receives a Pause or Stop message SCM creates a process for a service based on information stored in the Windows service database SCM sends a Start message to the service After a Windows service is started, it continues to run until it receives a Pause or Stop message
27
Windows Service Controller Program Starts,Stops, and Pauses a Windows service Resumes execution of a paused Windows service Queries the database to retrieve the status for a Windows service Starts,Stops, and Pauses a Windows service Resumes execution of a paused Windows service Queries the database to retrieve the status for a Windows service
28
Windows Service Controller Program (cont’d) Installs a new Windows service in the database Uninstalls an installed Windows service from the database Modifies the configuration information for a Windows service Installs a new Windows service in the database Uninstalls an installed Windows service from the database Modifies the configuration information for a Windows service
29
.NET Framework Support for Windows Services System.ServiceProcess namespace –Contains classes that enable ou to implement, install and control Windows services ServiceBase class –Provides the base-level functionality for a Windows services application System.ServiceProcess namespace –Contains classes that enable ou to implement, install and control Windows services ServiceBase class –Provides the base-level functionality for a Windows services application
30
.NET Framework Support for Windows Services (cont’d) ServiceProcessInstaller and ServiceInstaller classes –Enable you to use an installation utility such as installutil.exe to install a Windows service application ServiceController class –Enables a program to connect to a Windows service and perform various operations, such as Start, Stop and Query ServiceProcessInstaller and ServiceInstaller classes –Enable you to use an installation utility such as installutil.exe to install a Windows service application ServiceController class –Enables a program to connect to a Windows service and perform various operations, such as Start, Stop and Query
31
ServiceBase Class Provides basic functionality to a Windows service class Provides its derived classes with some well- knows methods and properties. SCM uses these methods and properties to communicate with Windows services Provides basic functionality to a Windows service class Provides its derived classes with some well- knows methods and properties. SCM uses these methods and properties to communicate with Windows services
32
Important Members of the ServiceBase Class Properties: –AutoLog –CanPauseAndContinue –CanShutDown –CanStop –EventLog –ServiceName Properties: –AutoLog –CanPauseAndContinue –CanShutDown –CanStop –EventLog –ServiceName
33
Important Members of the ServiceBase Class (cont’d) Methods: –OnContinue() –OnPause() –OnStart() –OnStop() –Run() Methods: –OnContinue() –OnPause() –OnStart() –OnStop() –Run()
34
Understanding How SCM Interacts With A Windows Service A Windows service contains one or more classes derived from ServiceBase Only one of these classes can have a Main() method Main() passes instances of the service to Run() Run() passes references to Windows service objects to the SCM SCM uses these objects to send messages to the Windows service A Windows service contains one or more classes derived from ServiceBase Only one of these classes can have a Main() method Main() passes instances of the service to Run() Run() passes references to Windows service objects to the SCM SCM uses these objects to send messages to the Windows service
35
Example: Start Message SCM finds the path of the Windows service executable file from the Windows service database SCM creates a Windows service process by executing Main() in the Windows service executable SCM finds the path of the Windows service executable file from the Windows service database SCM creates a Windows service process by executing Main() in the Windows service executable
36
Example: Start Message (cont’d) Main() creates one or more instances of the service class and passes their references to the SCM through the static Run() method The handler associated with the start message – OnStart() is executed –May listen to a port for incoming messages, log events to the event log, spool print jobs, etc. Main() creates one or more instances of the service class and passes their references to the SCM through the static Run() method The handler associated with the start message – OnStart() is executed –May listen to a port for incoming messages, log events to the event log, spool print jobs, etc.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.