Thursday, 15 November 2007

Chapter 8, lesson 3: Creating Windows Services.

  • WS - runs an assembly in the background without any user interaction. Run in own user session.
  • WS - can be automatically started on reboot, even if user does not log on.
  • 1. Cannot be debugged in VS. Must install, start, then attach debugger to service's process.
  • 2. Must create installation component for service apps - they install + register the svc on the server + create entry for svc with Windows Svc Control Manager.
  • 3. runs in a different 'window station' than the interactive station of the logged-on user. No dialog boxes + raise errors to event log, not UI.
  • 4. run in own security context. svc running under system account has more privileges than one under user account.

Creating a Service Project

  • There exists a Wisndows Svc app template in VS.
  • inherits from ServiceBase class.
  • OnStart, OnStop.
  • Add installers - 'Add Installer link in VS' - adds class with 2 - one to install process...

Implementing a Svc

  • ServiceBase.ServiceName property - set. ServiceName not friendly name - used by O.S. Must be unique.
  • OnStart - must not loop as has to return to O.S.
  • OnPause, OnContinue, OnShutdown. Optional.

Create an Install Project for a Service

  • Cannot simply run a svc exe. Must be installed <>
  • ServiceInstaller class - defines svc desc., display name, svc name, and start type.
  • ServiceProcessInstaller class - defines svc acc. settings. Security context set ~ Account property - 1. LocalService - nonprivileged user, 2. NetworkService - can authenticate to another comp on network, 3. LocalSystem - unlimited privileges, presents computer's credentials to any remote server.
  • VS automatically generates both above classes.

No comments: