1 ; from https://nsis.sourceforge.io/mediawiki/index.php?title=NSIS_Service_Lib&oldid=4726
2 ; un. functions disabled to prevent a NSIS warning
4 ; NSIS SERVICE LIBRARY - servicelib.nsh
5 ; Version 1.2 - 02/29/2004
6 ; Questions/Comments - dselkirk@hotmail.com
9 ; Provides an interface to window services
12 ; action - systemlib action ie. create, delete, start, stop, pause,
13 ; continue, installed, running, status
14 ; name - name of service to manipulate
15 ; param - action parameters; usage: var1=value1;var2=value2;...etc.
18 ; create - creates a new windows service
20 ; path - path to service executable
21 ; autostart - automatically start with system ie. 1|0
22 ; interact - interact with the desktop ie. 1|0
23 ; machine - machine name where to install service
24 ; user - user that runs the service
25 ; password - password of the above user
27 ; delete - deletes a windows service
28 ; start - start a stopped windows service
29 ; stop - stops a running windows service
30 ; pause - pauses a running windows service
31 ; continue - continues a paused windows service
32 ; installed - is the provided service installed
34 ; action - if true then invokes the specified action
35 ; running - is the provided service running
37 ; action - if true then invokes the specified action
38 ; status - check the status of the provided service
40 ; If run from uninstall define "UN" as "un." gefore running.
51 ; !insertmacro SERVICE "action" "name" "param"
54 ; 1.0 - 09/15/2003 - Initial release
55 ; 1.1 - 09/16/2003 - Changed &l to i, thx brainsucker
56 ; 1.2 - 02/29/2004 - Fixed documentation.
61 !define SC_MANAGER_ALL_ACCESS 0x3F
62 !define SERVICE_ALL_ACCESS 0xF01FF
64 !define SERVICE_CONTROL_STOP 1
65 !define SERVICE_CONTROL_PAUSE 2
66 !define SERVICE_CONTROL_CONTINUE 3
68 !define SERVICE_STOPPED 0x1
69 !define SERVICE_START_PENDING 0x2
70 !define SERVICE_STOP_PENDING 0x3
71 !define SERVICE_RUNNING 0x4
72 !define SERVICE_CONTINUE_PENDING 0x5
73 !define SERVICE_PAUSE_PENDING 0x6
74 !define SERVICE_PAUSED 0x7
80 !macro SERVICE ACTION NAME PARAM
104 IntCmp $3 $7 0 0 lbl_done
107 StrCmp $5 "$1=" 0 lbl_next
111 IntCmp $3 $7 0 0 lbl_done
113 StrCmp $6 ";" 0 lbl_next2
135 !macro CALL_GETPARAM VAR NAME DEFAULT LABEL
140 StrCpy ${VAR} "${DEFAULT}"
141 StrCmp $6 "" "${LABEL}" 0
145 !macro FUNC_SERVICE UN
166 System::Call 'advapi32::OpenSCManagerA(n, n, i ${SC_MANAGER_ALL_ACCESS}) i.r4'
168 StrCmp $3 "create" lbl_create
169 System::Call 'advapi32::OpenServiceA(i r4, t r2, i ${SERVICE_ALL_ACCESS}) i.r5'
173 StrCmp $3 "delete" lbl_delete
174 StrCmp $3 "start" lbl_start
175 StrCmp $3 "stop" lbl_stop
176 StrCmp $3 "pause" lbl_pause
177 StrCmp $3 "continue" lbl_continue
178 StrCmp $3 "installed" lbl_installed
179 StrCmp $3 "running" lbl_running
180 StrCmp $3 "status" lbl_status
192 !insertmacro CALL_GETPARAM $R1 "machine" "n" "lbl_machine"
195 !insertmacro CALL_GETPARAM $R2 "user" "n" "lbl_user"
198 !insertmacro CALL_GETPARAM $R3 "password" "n" "lbl_password"
201 !insertmacro CALL_GETPARAM $R4 "interact" "0x10" "lbl_interact"
208 !insertmacro CALL_GETPARAM $R5 "autostart" "0x3" "lbl_autostart"
215 !insertmacro CALL_GETPARAM $R6 "path" "n" "lbl_path"
218 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'
225 StrCmp $6 0 lbl_done lbl_good
229 System::Call 'advapi32::DeleteService(i r5) i.r6'
230 StrCmp $6 0 lbl_done lbl_good
234 System::Call 'advapi32::StartServiceA(i r5, i 0, i 0) i.r6'
235 StrCmp $6 0 lbl_done lbl_good
240 System::Call '*(i,i,i,i,i,i,i) i.R1'
241 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_STOP}, i $R1) i'
244 StrCmp $6 0 lbl_done lbl_good
249 System::Call '*(i,i,i,i,i,i,i) i.R1'
250 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_PAUSE}, i $R1) i'
253 StrCmp $6 0 lbl_done lbl_good
258 System::Call '*(i,i,i,i,i,i,i) i.R1'
259 System::Call 'advapi32::ControlService(i r5, i ${SERVICE_CONTROL_CONTINUE}, i $R1) i'
262 StrCmp $6 0 lbl_done lbl_good
266 !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
273 System::Call '*(i,i,i,i,i,i,i) i.R1'
274 System::Call 'advapi32::QueryServiceStatus(i r5, i $R1) i'
275 System::Call '*$R1(i, i.r6)'
279 StrCmp $6 ${SERVICE_RUNNING} 0 lbl_done
280 !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
286 System::Call '*(i,i,i,i,i,i,i) i.R1'
287 System::Call 'advapi32::QueryServiceStatus(i r5, i $R1) i'
288 System::Call '*$R1(i, i .r6)'
293 IntCmp $6 ${SERVICE_RUNNING} lbl_done
295 IntCmp $6 ${SERVICE_STOPPED} lbl_done
296 StrCpy $0 "start_pending"
297 IntCmp $6 ${SERVICE_START_PENDING} lbl_done
298 StrCpy $0 "stop_pending"
299 IntCmp $6 ${SERVICE_STOP_PENDING} lbl_done
301 IntCmp $6 ${SERVICE_RUNNING} lbl_done
302 StrCpy $0 "continue_pending"
303 IntCmp $6 ${SERVICE_CONTINUE_PENDING} lbl_done
304 StrCpy $0 "pause_pending"
305 IntCmp $6 ${SERVICE_PAUSE_PENDING} lbl_done
307 IntCmp $6 ${SERVICE_PAUSED} lbl_done
314 System::Call 'advapi32::CloseServiceHandle(i r5) n'
316 System::Call 'advapi32::CloseServiceHandle(i r4) n'
329 !insertmacro FUNC_SERVICE ""
332 ; Function un.Service
333 ; !insertmacro FUNC_SERVICE "un."
337 !insertmacro FUNC_GETPARAM
340 ; Function un.GetParam
341 ; !insertmacro FUNC_GETPARAM