-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Windows service applications -- -- This package provides a partial binding to the Win32 System Services -- API. It makes it easy to write Windows service applications using -- Haskell. _This is the first version that supports both 32-bit and -- 64-bit versions of GHC._ -- -- The binding is partial. Here are a few ways in which it differs from -- the official API: -- -- -- -- Effort has been made to simplify using the API without hiding what is -- happening behind the scenes. Users are encouraged to read Microsoft's -- documentation under 'Dev Center - Desktop > Docs > Desktop app -- development documentation > System Services > Services'. The -- official example has been ported to Haskell. This can be found in the -- examples directory of the source tree. -- -- Simple Example and Usage -- --
--   module Main where
--   
--   import Control.Concurrent.MVar
--   import System.Win32.Services
--   
--   main = do
--       mStop <- newEmptyMVar
--       startServiceCtrlDispatcher "Test" 3000 (handler mStop) $ \_ _ h -> do
--           setServiceStatus h running
--           takeMVar mStop
--           setServiceStatus h stopped
--   
--   handler mStop hStatus Stop = do
--       setServiceStatus hStatus stopPending
--       putMVar mStop ()
--       return True
--   handler _ _ Interrogate = return True
--   handler _ _ _           = return False
--   
--   running = ServiceStatus Win32OwnProcess Running [AcceptStop] nO_ERROR 0 0 0
--   stopped = ServiceStatus Win32OwnProcess Stopped [] nO_ERROR 0 0 0
--   stopPending = ServiceStatus Win32OwnProcess StopPending [AcceptStop] nO_ERROR 0 0 0
--   
-- --
--   C:programmingtest>ghc --make -threaded Main.hs
--   [1 of 1] Compiling Main             ( Main.hs, Main.o )
--   Linking Main.exe ...
--   <linker warnings omitted>
--   C:\programming\test>copy Main.exe c:\svc\Test.exe
--   1 file(s) copied.
--   
-- -- Execute the following from an elevated command prompt to register the -- service: -- --
--   C:\svc>sc create Test binPath= c:\svc\Test.exe
--   [SC] CreateService SUCCESS
--   
-- -- The service can now be started and stopped from the services console. -- -- Installation Notes: -- -- Depending on which version of GHC you are using you may also need to -- add a extra-lib-dirs directive. In GHC version 8.4.3 it works out of -- the box with the libadvapi32.a file in -- ...\mingw\x86_64-w64-mingw32\lib. For older version you need to use a -- version from a Windows SDK. Your .cabal file will then need to be -- modified before installing. A simple `cabal install Win32-services` -- may not work. For example, If you are building on Windows 8 64-bit -- with the Windows 8 SDK the 'extra-lib-dirs' field will need to be -- changed to read as follows: -- --
--   Extra-Lib-Dirs: "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x86"
--   
-- -- If building with stack an option is to set it in stack.yaml. For -- example with the Windows 10 SDK installed with Build Tools for Visual -- Studio 2017: -- --
--   extra-lib-dirs:
--   - C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64
--   
@package Win32-services @version 0.4 module System.Win32.Services -- | A handler function is registered with the service dispatcher thread -- from a ServiceMainFunction. The first argument is a -- HANDLE returned from calling -- registerServiceCtrlHandler. The second argument represents -- the command this service has been directed to perform. type HandlerFunction = HANDLE -> ServiceControl -> IO Bool -- | The service dispatcher thread will call each function of this type -- that you provide. The first argument will be the name of the service. -- Any additional command-line parameters will appear in the second -- argument. -- -- Each of these functions should call -- registerServiceCtrlHandler to register a function to handle -- incoming commands. It should then set the service's status to -- StartPending, and specify that no controls will be accepted. At -- this point the function may perform any other initialization steps -- before setting the service's status to Running. All of this -- should take no more than 100ms. type ServiceMainFunction = String -> [String] -> HANDLE -> IO () -- | The control codes the service accepts and processes in its handler -- function (See HandlerFunction). By default, all services -- accept the Interrogate value. To accept the -- DEVICEEVENT value, the service must register to receive -- device events by using the registerDeviceNotification -- function. data ServiceAccept -- | The service is a network component that can accept changes in its -- binding without being stopped and restarted. This control code allows -- the service to receive NetBindAdd, NetBindRemove, -- NetBindEnable, and NetBindDisable notifications. AcceptNetBindChange :: ServiceAccept -- | The service can reread its startup parameters without being stopped -- and restarted. This control code allows the service to receive -- ParamChange notifications. AcceptParamChange :: ServiceAccept -- | The service can be paused and continued. This control code allows the -- service to receive Pause and Continue notifications. AcceptPauseContinue :: ServiceAccept -- | MSDN documentation says that this function is not supported on Windows -- Server 2003 or Windows XP/2000. The support status on other versions -- is unknown to me. -- -- The service can perform preshutdown tasks. This control code enables -- the service to receive Preshutdown notifications. Note that -- only the system can send it. AcceptPreshutdown :: ServiceAccept -- | The service is notified when system shutdown occurs. This control code -- allows the service to receive Shutdown notifications. Note that -- only the system can send it. AcceptShutdown :: ServiceAccept -- | The service can be stopped. This control code allows the service to -- receive Stop notifications. AcceptStop :: ServiceAccept -- | A ServiceControl is used in Handler functions. All control codes are -- defined here, but some can only be used with a HandlerEx -- callback. Use convertSuccess to translate from a -- ServiceControl to a DWORD. Use convertAttempt -- to translate from a DWORD to a ServiceControl. data ServiceControl Continue :: ServiceControl Interrogate :: ServiceControl NetBindAdd :: ServiceControl NetBindDisable :: ServiceControl NetBindEnable :: ServiceControl NetBindRemove :: ServiceControl ParamChange :: ServiceControl Pause :: ServiceControl PreShutdown :: ServiceControl Shutdown :: ServiceControl Stop :: ServiceControl -- | The current state of a service. data ServiceState ContinuePending :: ServiceState PausePending :: ServiceState Paused :: ServiceState Running :: ServiceState StartPending :: ServiceState StopPending :: ServiceState Stopped :: ServiceState -- | Contains status information for a service. data ServiceStatus ServiceStatus :: ServiceType -> ServiceState -> [ServiceAccept] -> ErrCode -> DWORD -> DWORD -> DWORD -> ServiceStatus -- | The type of service. This binding only supports the -- Win32OwnProcess type. [serviceType] :: ServiceStatus -> ServiceType -- | The current state of the service. [currentState] :: ServiceStatus -> ServiceState -- | See ServiceAccept for details on this field. [controlsAccepted] :: ServiceStatus -> [ServiceAccept] -- | The error code the service uses to report an error that occurs when it -- is starting or stopping. To return an error code specific to the -- service, the service must set this value to -- ServiceSpecificError to indicate that the -- serviceSpecificExitCode member contains the error code. The -- service should set this value to Success when it is running and -- on normal termination. [win32ExitCode] :: ServiceStatus -> ErrCode -- | A service-specific error code that the service returns when an error -- occurs while the service is starting or stopping. This value is -- ignored unless the win32ExitCode member is set to -- ServiceSpecificError. -- -- This binding does not support service-specific error codes. [serviceSpecificExitCode] :: ServiceStatus -> DWORD -- | The check-point value the service increments periodically to report -- its progress during a lengthy start, stop, pause, or continue -- operation. For example, the service should increment this value as it -- completes each step of its initialization when it is starting up. The -- user interface program that invoked the operation on the service uses -- this value to track the progress of the service during a lengthy -- operation. This value is not valid and should be zero when the service -- does not have a start, stop, pause, or continue operation pending. [checkPoint] :: ServiceStatus -> DWORD -- | The estimated time required for a pending start, stop, pause, or -- continue operation, in milliseconds. Before the specified amount of -- time has elapsed, the service should make its next call to the -- SetServiceStatus function with either an incremented dwCheckPoint -- value or a change in currentState. If the amount of time -- specified by waitHint passes, and checkPoint has not -- been incremented or currentState has not changed, the service -- control manager or service control program can assume that an error -- has occurred and the service should be stopped. However, if the -- service shares a process with other services, the service control -- manager cannot terminate the service application because it would have -- to terminate the other services sharing the process as well. [waitHint] :: ServiceStatus -> DWORD -- | Win32 defines many types of services, but this binding only supports -- Win32OwnProcess. data ServiceType -- | The service is a file system driver. FileSystemDriver :: ServiceType -- | The service is a device driver. KernelDriver :: ServiceType -- | The service runs in its own process. Win32OwnProcess :: ServiceType -- | The service shares a process with other services. Win32ShareProcess :: ServiceType -- | Do no write your own services of this type. Windows Vista and above -- prevent service processes from directly interacting with users. -- -- A ServiceInteractiveProcess is either a Win32OwnProcess -- or a Win32ShareProcess running in the context of the -- LocalSystem account which is allowed to directly interact with users. ServiceInteractiveProcess :: ServiceType -- | Retrieves the current status of the specified service. queryServiceStatus :: HANDLE -> IO ServiceStatus -- | Updates the service control manager's status information for the -- calling service. setServiceStatus :: HANDLE -> ServiceStatus -> IO () -- | Register a callback function to initialize the service, which will be -- called by the operating system immediately. startServiceCtrlDispatcher -- will block until the provided callback function returns. -- -- MSDN documentation: Connects the main thread of a service process to -- the service control manager, which causes the thread to be the service -- control dispatcher thread for the calling process. startServiceCtrlDispatcher :: String -> DWORD -> HandlerFunction -> ServiceMainFunction -> IO ()