Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / packaging / nsis / servicelib.nsh
blob55f5116aa0dab6c70879a3872b999d8b2c4cad79
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
8 ; Description:
9 ;   Provides an interface to window services
11 ; Inputs:
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.
17 ; Actions:
18 ;   create      - creates a new windows service
19 ;               Parameters:
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
33 ;               Parameters:
34 ;                 action        - if true then invokes the specified action
35 ;   running     - is the provided service running
36 ;               Parameters:
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.
42 ; Usage:
43 ;   Method 1:
44 ;     Push "action"
45 ;     Push "name"
46 ;     Push "param"
47 ;     Call Service
48 ;     Pop $0 ;response
50 ;   Method 2:
51 ;     !insertmacro SERVICE "action" "name" "param"
53 ; History:
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.
58 !ifndef SERVICELIB
59   !define SERVICELIB
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
76   !ifndef UN
77     !define UN ""
78   !endif
80   !macro SERVICE ACTION NAME PARAM
81     Push '${ACTION}'
82     Push '${NAME}'
83     Push '${PARAM}'
84     Call ${UN}Service
85   !macroend
87   !macro FUNC_GETPARAM
88     Push $0
89     Push $1
90     Push $2
91     Push $3
92     Push $4
93     Push $5
94     Push $6
95     Push $7
96     Exch 8
97     Pop $1 ;name
98     Exch 8
99     Pop $2 ;source
100     StrCpy $0 ""
101     StrLen $7 $2
102     StrCpy $3 0
103     lbl_loop:
104       IntCmp $3 $7 0 0 lbl_done
105       StrLen $4 "$1="
106       StrCpy $5 $2 $4 $3
107       StrCmp $5 "$1=" 0 lbl_next
108       IntOp $5 $3 + $4
109       StrCpy $3 $5
110       lbl_loop2:
111         IntCmp $3 $7 0 0 lbl_done
112         StrCpy $6 $2 1 $3
113         StrCmp $6 ";" 0 lbl_next2
114         IntOp $6 $3 - $5
115         StrCpy $0 $2 $6 $5
116         Goto lbl_done
117         lbl_next2:
118         IntOp $3 $3 + 1
119         Goto lbl_loop2
120       lbl_next:
121       IntOp $3 $3 + 1
122       Goto lbl_loop
123     lbl_done:
124     Pop $5
125     Pop $4
126     Pop $3
127     Pop $2
128     Pop $1
129     Exch 2
130     Pop $6
131     Pop $7
132     Exch $0
133   !macroend
135   !macro CALL_GETPARAM VAR NAME DEFAULT LABEL
136     Push $1
137     Push ${NAME}
138     Call ${UN}GETPARAM
139     Pop $6
140     StrCpy ${VAR} "${DEFAULT}"
141     StrCmp $6 "" "${LABEL}" 0
142     StrCpy ${VAR} $6
143   !macroend
145   !macro FUNC_SERVICE UN
146     Push $0
147     Push $1
148     Push $2
149     Push $3
150     Push $4
151     Push $5
152     Push $6
153     Push $7
154     Exch 8
155     Pop $1 ;param
156     Exch 8
157     Pop $2 ;name
158     Exch 8
159     Pop $3 ;action
160     ;$0 return
161     ;$4 OpenSCManager
162     ;$5 OpenService
165     StrCpy $0 "false"
166     System::Call 'advapi32::OpenSCManagerA(n, n, i ${SC_MANAGER_ALL_ACCESS}) i.r4'
167     IntCmp $4 0 lbl_done
168     StrCmp $3 "create" lbl_create
169     System::Call 'advapi32::OpenServiceA(i r4, t r2, i ${SERVICE_ALL_ACCESS}) i.r5'
170     IntCmp $5 0 lbl_done
172     lbl_select:
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
181     Goto lbl_done
183     ; create service
184     lbl_create:
185       Push $R1 ;machine
186       Push $R2 ;user
187       Push $R3 ;password
188       Push $R4 ;interact
189       Push $R5 ;autostart
190       Push $R6 ;path
192       !insertmacro CALL_GETPARAM $R1 "machine" "n" "lbl_machine"
193       lbl_machine:
195       !insertmacro CALL_GETPARAM $R2 "user" "n" "lbl_user"
196       lbl_user:
198       !insertmacro CALL_GETPARAM $R3 "password" "n" "lbl_password"
199       lbl_password:
201       !insertmacro CALL_GETPARAM $R4 "interact" "0x10" "lbl_interact"
202         StrCpy $6 0x10
203         IntCmp $R4 0 +2
204         IntOp $R4 $6 | 0x100
205         StrCpy $R4 $6
206       lbl_interact:
208       !insertmacro CALL_GETPARAM $R5 "autostart" "0x3" "lbl_autostart"
209         StrCpy $6 0x3
210         IntCmp $R5 0 +2
211         StrCpy $6 0x2
212         StrCpy $R5 $6
213       lbl_autostart:
215       !insertmacro CALL_GETPARAM $R6 "path" "n" "lbl_path"
216       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'
219       Pop $R6
220       Pop $R5
221       Pop $R4
222       Pop $R3
223       Pop $R2
224       Pop $R1
225       StrCmp $6 0 lbl_done lbl_good
227     ; delete service
228     lbl_delete:
229       System::Call 'advapi32::DeleteService(i r5) i.r6'
230       StrCmp $6 0 lbl_done lbl_good
232     ; start service
233     lbl_start:
234       System::Call 'advapi32::StartServiceA(i r5, i 0, i 0) i.r6'
235       StrCmp $6 0 lbl_done lbl_good
237     ; stop service
238     lbl_stop:
239       Push $R1
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'
242       System::Free $R1
243       Pop $R1
244       StrCmp $6 0 lbl_done lbl_good
246     ; pause service
247     lbl_pause:
248       Push $R1
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'
251       System::Free $R1
252       Pop $R1
253       StrCmp $6 0 lbl_done lbl_good
255     ; continue service
256     lbl_continue:
257       Push $R1
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'
260       System::Free $R1
261       Pop $R1
262       StrCmp $6 0 lbl_done lbl_good
264     ; is installed
265     lbl_installed:
266       !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
267         StrCpy $3 $7
268         Goto lbl_select
270     ; is service running
271     lbl_running:
272       Push $R1
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)'
276       System::Free $R1
277       Pop $R1
278       IntFmt $6 "0x%X" $6
279       StrCmp $6 ${SERVICE_RUNNING} 0 lbl_done
280       !insertmacro CALL_GETPARAM $7 "action" "" "lbl_good"
281         StrCpy $3 $7
282         Goto lbl_select
284     lbl_status:
285       Push $R1
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)'
289       System::Free $R1
290       Pop $R1
291       IntFmt $6 "0x%X" $6
292       StrCpy $0 "running"
293       IntCmp $6 ${SERVICE_RUNNING} lbl_done
294       StrCpy $0 "stopped"
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
300       StrCpy $0 "running"
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
306       StrCpy $0 "paused"
307       IntCmp $6 ${SERVICE_PAUSED} lbl_done
308       StrCpy $0 "unknown"
310     lbl_good:
311     StrCpy $0 "true"
312     lbl_done:
313     IntCmp $5 0 +2
314     System::Call 'advapi32::CloseServiceHandle(i r5) n'
315     IntCmp $4 0 +2
316     System::Call 'advapi32::CloseServiceHandle(i r4) n'
317     Pop $4
318     Pop $3
319     Pop $2
320     Pop $1
321     Exch 3
322     Pop $5
323     Pop $6
324     Pop $7
325     Exch $0
326   !macroend
328   Function Service
329     !insertmacro FUNC_SERVICE ""
330   FunctionEnd
332 ;  Function un.Service
333 ;    !insertmacro FUNC_SERVICE "un."
334 ;  FunctionEnd
336   Function GetParam
337     !insertmacro FUNC_GETPARAM
338   FunctionEnd
340 ;  Function un.GetParam
341 ;    !insertmacro FUNC_GETPARAM
342 ;  FunctionEnd
344 !endif