Thursday, March 31, 2005
Hansleman's List: Services and Executables
More from Scott Hansleman's list of what great developers should know: What is a Windows Service and how does its lifecycle differ from a "standard" EXE? A Windows Service (NT Service, formerly) is a process conforming to Service Control Manager interface rules. (Kalani) It's not just a normal executable started from a command line; a Windows Service must use the Service Control Manager's installer component to register with the SCM. Services are generally console apps with no User Interface. Interactive Services are highly discouraged, especially if running under the SYSTEM context. Services can start before a user logs on, and have a different security context than users. Take care when choosing the account to run a Service. LocalService or NetworkService recommended. (Howard, 2003) (Make sure you read this book for overall security issues, not just Service-related ones.) Services have their own process, or can share a process with other services. A Service can't be debugged directly in Visual Studio using the Run command. A service must first be installed, then started, after which the debugger can be attached to it. (MSDN, Introduction to Windows Service Applications) As for lifecycle, Services are started automatically, manually or programmatically and can be paused or stopped in the same fashion. See MSDN's Windows Service Applications for a good overview and starting point.