forked from mikesteele81/Win32-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWin32-services.cabal
More file actions
156 lines (152 loc) · 5.65 KB
/
Win32-services.cabal
File metadata and controls
156 lines (152 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Win32-services
category: System
version: 0.4.0.1
cabal-version: 1.16
build-type: Simple
author: Michael Steele
maintainer: Michael Steele <mikesteele81@gmail.com>
copyright: Copyright 2011-2018 Michael Steele
homepage: http://github.com/mikesteele81/win32-services
bug-reports: http://github.com/mikesteele81/win32-services/issues
license: BSD3
license-file: LICENSE
tested-with: GHC == 7.6.3, GHC == 7.8.3, GHC == 7.10.1, GHC == 8.2.2, GHC == 8.4.3, GHC == 8.6.5
stability: provisional
synopsis: Windows service applications
description:
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
@
.
extra-source-files:
changelog
examples/*.hs
source-repository head
type: git
location: git://github.com/mikesteele81/win32-services.git
library
build-depends: base >= 4.5 && < 5.0
, Win32 >= 2.2
, Win32-errors >= 0.2
default-language: Haskell2010
ghc-options: -Wall
hs-source-dirs: src
Exposed-Modules: System.Win32.Services
Extra-Libraries: Advapi32
-- Extra-Lib-Dirs: "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x86"
-- Extra-Lib-Dirs: "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x64"
-- Extra-Lib-Dirs: "C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.15063.0\\um\\x64\\AdvAPI32.Lib"
-- Extra-Lib-Dirs: c:\Windows\System32
other-modules:
Import
, System.Win32.Services.Raw
, System.Win32.Services.Accept
, System.Win32.Services.Control
, System.Win32.Services.State
, System.Win32.Services.Status
, System.Win32.Services.TableEntry
, System.Win32.Services.Type
-- executable SimpleExample
-- hs-source-dirs: examples
-- main-is: simple.hs
-- ghc-options: -threaded -rtsopts -with-rtsopts=-N
-- build-depends: base, Win32-services, Win32-errors
-- default-language: Haskell2010
--
-- executable OfficialExample
-- hs-source-dirs: examples
-- main-is: official.hs
-- ghc-options: -threaded -rtsopts -with-rtsopts=-N -eventlog
-- build-depends: base, Win32-services, Win32, Win32-errors
-- default-language: Haskell2010