Win32-services
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 version 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:
* Only services running within their own process are supported. These are
processes of the "WIN32_OWN_PROCESS" type.
* In cases where multiple versions of the same function exist (for
compatibility), this binding only offers one of them.
* None of the extended control codes are supported. Handlers you write will
automatically report this to the operating system when such controls are
received.
* Only facilities for writing services are supported; not controlling them.
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:\programming\test\>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
@
| version | uploaded | uploader | changes | |
|---|---|---|---|---|
| 0.4.0.1 | 2019-05-15 17:58 UTC | gussen | 1 revisions | +8/−4 lines, 2 filesdep ~Win32PVP ok |
| 0.4 | 2018-07-24 10:46 UTC | gussen | +117/−31 lines, 8 filesdep ~Win32dep ~basesetup-changednew-uploader | |
| 0.3 | 2015-05-25 21:37 UTC | MichaelSteele | +654/−640 lines, 21 filesdep +Win32-errors | |
| 0.2.5.1 | 2015-04-02 15:16 UTC | MichaelSteele | +33/−15 lines, 6 filesPVP ok | |
| 0.2.5 | 2015-03-31 20:05 UTC | MichaelSteele | +738/−721 lines, 12 filesdep −errorsdep ~base | |
| 0.2.4 | 2014-06-03 23:53 UTC | MichaelSteele | +606/−600 lines, 11 filesdep ~Win32dep ~errors | |
| 0.2.3.1 | 2014-02-25 01:28 UTC | MichaelSteele | +43/−2 lines, 2 files | |
| 0.2.3 | 2014-02-25 01:23 UTC | MichaelSteele | +124/−157 lines, 2 filesdep ~base | |
| 0.2.2.1 | 2013-08-26 18:10 UTC | MichaelSteele | +2/−2 lines, 1 files | |
| 0.2.2 | 2013-08-26 17:22 UTC | MichaelSteele | +750/−746 lines, 9 filesdep ~base | |
| 0.2.1 | 2013-04-07 21:33 UTC | MichaelSteele | +88/−82 lines, 7 files | |
| 0.2 | 2013-03-17 01:14 UTC | MichaelSteele | +797/−742 lines, 12 files | |
| 0.1 | 2013-03-15 00:37 UTC | MichaelSteele | +790/−0 lines, 14 filesdep +Win32dep +basedep +errorssetup-changed |
Dependencies of Win32-services-0.4.0.1
Win32 >=2.2 && <2.15 2.14.2.1 → 2.14.2.2
| 2026-05-27 18:35 UTC | 2.14.2.2 | +8/−5 lines, 4 filesPVP ok |
| 2025-06-23 19:51 UTC | 2.14.2.1 | +17/−3 lines, 4 filesPVP ok |
| 2025-05-31 06:32 UTC | 2.14.2.0 | +260/−13 lines, 10 filesPVP ok |
| 2024-11-12 20:10 UTC | 2.14.1.0 | +235/−11 lines, 11 filesPVP ok |
| 2024-01-13 23:14 UTC | 2.14.0.0 | +740/−208 lines, 13 filesdep +os-stringdep ~filepath |
showing 5 of 49 versions
Win32-errors >=0.2 && <0.3 0.2.2.6 → 0.2.2.7
| 2023-04-05 20:52 UTC | 0.2.2.7 | +11/−8 lines, 3 filesdep ~Win32dep ~template-haskelldep ~textPVP ok |
| 2023-04-05 20:43 UTC | 0.2.2.6 | +14/−5 lines, 2 filesdep ~Win32dep ~template-haskellPVP ok |
| 2019-09-15 19:04 UTC | 0.2.2.5 | +11/−6 lines, 2 filesdep ~Win32dep ~template-haskellPVP ok |
| 2019-05-12 11:10 UTC | 0.2.2.4 | +8/−4 lines, 2 filesdep ~Win32dep ~template-haskellPVP ok |
| 2018-07-20 15:35 UTC | 0.2.2.3 | +500/−428 lines, 11 filesdep +QuickCheckdep +Win32-errorsdep +hspecdep ~Win32dep ~basedep ~template-haskellsetup-changednew-uploaderPVP: major bump suggested |
showing 5 of 11 versions
base >=4.5 && <5.0 4.22.0.0 → 4.22.1.0
| 2026-12-01 12:38 UTC | 4.22.1.0 | +388/−6 lines, 9 filesdep ~ghc-internalPVP: major bump suggested |
| 2025-12-19 11:52 UTC | 4.22.0.0 | +886/−215 lines, 28 filesdep ~ghc-internalPVP ok |
| 2026-03-27 12:26 UTC | 4.21.2.0 | +10/−3 lines, 4 filesdep ~ghc-internalPVP ok |
| 2025-12-27 10:31 UTC | 4.21.1.0 | +17/−5 lines, 4 filesdep ~ghc-internalPVP ok |
| 2024-12-16 09:24 UTC | 4.21.0.0 | +1170/−396 lines, 39 filesdep ~ghc-internalPVP ok |
showing 5 of 61 versions
Reverse dependencies
1 packages depend on Win32-services; 1 have bounds that exclude 0.4.0.1