2 ; NSIS SERVICE LIBRARY - servicelib.nsh
3 ; Version 1.2 - 02/29/2004
4 ; Questions/Comments - dselkirk@hotmail.com
7 ; Provides an interface to window services
10 ; action - systemlib action ie. create, delete, start, stop, pause,
11 ; continue, installed, running, status
12 ; name - name of service to manipulate
13 ; param - action parameters; usage: var1=value1;var2=value2;...etc.
16 ; create - creates a new windows service
18 ; path - path to service executable
19 ; autostart - automatically start with system ie. 1|0
20 ; interact - interact with the desktop ie. 1|0
21 ; machine - machine name where to install service
22 ; user - user that runs the service
23 ; password - password of the above user
25 ; delete - deletes a windows service
26 ; start - start a stopped windows service
27 ; stop - stops a running windows service
28 ; pause - pauses a running windows service
29 ; continue - continues a paused windows service
30 ; installed - is the provided service installed
32 ; action - if true then invokes the specified action
33 ; running - is the provided service running
35 ; action - if true then invokes the specified action
36 ; status - check the status of the provided service
38 ; If run from uninstall define "UN" as "un." gefore running.
49 ; !insertmacro SERVICE "action" "name" "param"
52 ; 1.0 - 09/15/2003 - Initial release
53 ; 1.1 - 09/16/2003 - Changed &l to i, thx brainsucker
54 ; 1.2 - 02/29/2004 - Fixed documentation.
59 !define SC_MANAGER_ALL_ACCESS 0x3F
60 !define SERVICE_ALL_ACCESS 0xF01FF
62 !define SERVICE_CONTROL_STOP 1
63 !define SERVICE_CONTROL_PAUSE 2
64 !define SERVICE_CONTROL_CONTINUE 3
66 !define SERVICE_STOPPED 0x1
67 !define SERVICE_START_PENDING 0x2
68 !define SERVICE_STOP_PENDING 0x3
69 !define SERVICE_RUNNING 0x4
70 !define SERVICE_CONTINUE_PENDING 0x5
71 !define SERVICE_PAUSE_PENDING 0x6
72 !define SERVICE_PAUSED 0x7
78 !macro SERVICE ACTION NAME PARAM
102 IntCmp $3 $7 0 0 lbl_done
105 StrCmp $5 "$1=" 0 lbl_next
109 IntCmp $3 $7 0 0 lbl_done
111 StrCmp $6 ";" 0 lbl_next2
133 !macro CALL_GETPARAM VAR NAME DEFAULT LABEL
138 StrCpy ${VAR} "${DEFAULT}"
139 StrCmp $6 "" "${LABEL}" 0
143 !macro FUNC_SERVICE UN
164 System::Call 'advapi32::OpenSCManagerA(n, n, i ${SC_MANAGER_ALL_ACCESS}) i.r4'
166 StrCmp $3 "create" lbl_create
167 System::Call 'advapi32::OpenServiceA(i r4, t r2, i ${SERVICE_ALL_ACCESS}) i.r5'
171 StrCmp $3 "delete" lbl_delete
172 StrCmp $3 "start" lbl_start
173 StrCmp $3 "stop" lbl_stop
174 StrCmp $3 "pause" lbl_pause
175 StrCmp $3 "continue" lbl_continue
176 StrCmp $3 "installed" lbl_installed
177 StrCmp $3 "running" lbl_running
178 StrCmp $3 "status" lbl_status
190 !insertmacro CALL_GETPARAM $R1 "machine" "n" "lbl_machine"
193 !insertmacro CALL_GETPARAM $R2 "user" "n" "lbl_user"
196 !insertmacro CALL_GETPARAM $R3 "password" "n" "lbl_password"
199 !insertmacro CALL_GETPARAM $R4 "interact" "0x10" "lbl_interact"
206 !insertmacro CALL_GETPARAM $R5 "autostart" "0x3" "lbl_autostart"
213 !insertmacro CALL_GETPARAM $R6 "path" "n" "lbl_path"
216 System::Call 'advapi32::CreateServiceA(i r4, t r2, t r2, i ${SERVICE_ALL_ACCESS}, i R4, i R5, i 0, t R6, n, n, R1, R2, R3) i.r6'
223 StrCmp $6 0 lbl_done lbl_good
227 System::Call 'advapi32::DeleteService(i r5) i.r6'
228 StrCmp $6 0 lbl_done lbl_good
232 System::Call 'advapi32::StartServiceA(i r5, i 0, i 0) i.r6'
233 StrCmp $6 0 lbl_done lbl_good
238 System::Call '*(i,i,i,i,i,i,i) i.R1'
239 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_STOP}, i $R1) i'
242 StrCmp $6 0 lbl_done lbl_good
247 System::Call '*(i,i,i,i,i,i,i) i.R1'
248 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_PAUSE}, i $R1) i'
251 StrCmp $6 0 lbl_done lbl_good
256 System::Call '*(i,i,i,i,i,i,i) i.R1'
257 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_CONTINUE}, i $R1) i'
260 StrCmp $6 0 lbl_done lbl_good
264 !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
271 System::Call '*(i,i,i,i,i,i,i) i.R1'
272 System::Call 'advapi32::QueryServiceStatus(i r5, i $R1) i'
273 System::Call '*$R1(i, i.r6)'
277 StrCmp $6 ${SERVICE_RUNNING} 0 lbl_done
278 !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
284 System::Call '*(i,i,i,i,i,i,i) i.R1'
285 System::Call 'advapi32::QueryServiceStatus(i r5, i $R1) i'
286 System::Call '*$R1(i, i .r6)'
291 IntCmp $6 ${SERVICE_RUNNING} lbl_done
293 IntCmp $6 ${SERVICE_STOPPED} lbl_done
294 StrCpy $0 "start_pending"
295 IntCmp $6 ${SERVICE_START_PENDING} lbl_done
296 StrCpy $0 "stop_pending"
297 IntCmp $6 ${SERVICE_STOP_PENDING} lbl_done
299 IntCmp $6 ${SERVICE_RUNNING} lbl_done
300 StrCpy $0 "continue_pending"
301 IntCmp $6 ${SERVICE_CONTINUE_PENDING} lbl_done
302 StrCpy $0 "pause_pending"
303 IntCmp $6 ${SERVICE_PAUSE_PENDING} lbl_done
305 IntCmp $6 ${SERVICE_PAUSED} lbl_done
312 System::Call 'advapi32::CloseServiceHandle(i r5) n'
314 System::Call 'advapi32::CloseServiceHandle(i r4) n'
327 !insertmacro FUNC_SERVICE ""
331 !insertmacro FUNC_SERVICE "un."
335 !insertmacro FUNC_GETPARAM
339 !insertmacro FUNC_GETPARAM