The Win32-services package

[Tags: bsd3, library]

This package provides a partial binding to the Win32 System Services API. It's now possible to write Windows service applications using Haskell.

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.SystemServices.Services

main = do
    mStop <- newEmptyMVar
    startServiceCtrlDispatcher "Test" 3000 (handler mStop) $ \_ _ h -> do
        setServiceStatus h running
        takeMVar mStop

handler mStop hStatus STOP = do
    setServiceStatus hStatus stopPending
    putMVar mStop ()
    return True
handler _ _ INTERROGATE = return True
handler _ _ _           = return False

stopPending = running { currentState = STOP_PENDING
                      , controlsAccepted = []
                      , waitHint = 3000 }
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 Windows and the Windows SDK you are using the .cabal file will 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"

Release Notes:

Changes in 0.2

Changes in 0.1


Versions0.1, 0.2, 0.2.1, 0.2.2,, 0.2.3,, 0.2.4, 0.2.5,, 0.3 (info)
Change logNone available
Dependenciesbase (==4.5.*), errors, Win32 [details]
CopyrightCopyright (C) 2011-2013 Michael Steele
AuthorMichael Steele
MaintainerMichael Steele <>
Home page
Bug tracker
Source repositoryhead: git clone git://
UploadedSun Mar 17 01:14:52 UTC 2013 by MichaelSteele
Downloads2130 total (37 in last 30 days)
0 []
StatusDocs not available [build log]
All reported builds failed as of 2015-12-08 [all 5 reports]



Maintainers' corner

For package maintainers and hackage trustees