|
15 | 15 |
|
16 | 16 |
|
17 | 17 | //Update this when releasing a new version
|
18 |
| -#define public Version '1.2.0' |
| 18 | +#define public Version '1.2.1' |
19 | 19 |
|
20 | 20 | //This defines in which sub folder of this project the current files are located
|
21 | 21 | #define public HackMonospaced_Sourcefolder 'Hack_v2_020'
|
@@ -269,47 +269,10 @@ Type: files; Name: "{app}\Log*.txt"
|
269 | 269 |
|
270 | 270 |
|
271 | 271 | [Code]
|
272 |
| -type |
273 |
| - SERVICE_STATUS = record |
274 |
| - dwServiceType : cardinal; |
275 |
| - dwCurrentState : cardinal; |
276 |
| - dwControlsAccepted : cardinal; |
277 |
| - dwWin32ExitCode : cardinal; |
278 |
| - dwServiceSpecificExitCode : cardinal; |
279 |
| - dwCheckPoint : cardinal; |
280 |
| - dwWaitHint : cardinal; |
281 |
| - end; |
282 |
| - HANDLE = cardinal; |
283 |
| -
|
284 |
| -const |
285 |
| - SERVICE_QUERY_CONFIG = $1; |
286 |
| - SERVICE_CHANGE_CONFIG = $2; |
287 |
| - SERVICE_QUERY_STATUS = $4; |
288 |
| - SERVICE_START = $10; |
289 |
| - SERVICE_STOP = $20; |
290 |
| - SERVICE_ALL_ACCESS = $f01ff; |
291 |
| - SC_MANAGER_ALL_ACCESS = $f003f; |
292 |
| - SERVICE_WIN32_OWN_PROCESS = $10; |
293 |
| - SERVICE_WIN32_SHARE_PROCESS = $20; |
294 |
| - SERVICE_WIN32 = $30; |
295 |
| - SERVICE_INTERACTIVE_PROCESS = $100; |
296 |
| - SERVICE_BOOT_START = $0; |
297 |
| - SERVICE_SYSTEM_START = $1; |
298 |
| - SERVICE_AUTO_START = $2; |
299 |
| - SERVICE_DEMAND_START = $3; |
300 |
| - SERVICE_DISABLED = $4; |
301 |
| - SERVICE_DELETE = $10000; |
302 |
| - SERVICE_CONTROL_STOP = $1; |
303 |
| - SERVICE_CONTROL_PAUSE = $2; |
304 |
| - SERVICE_CONTROL_CONTINUE = $3; |
305 |
| - SERVICE_CONTROL_INTERROGATE = $4; |
306 |
| - SERVICE_STOPPED = $1; |
307 |
| - SERVICE_START_PENDING = $2; |
308 |
| - SERVICE_STOP_PENDING = $3; |
309 |
| - SERVICE_RUNNING = $4; |
310 |
| - SERVICE_CONTINUE_PENDING = $5; |
311 |
| - SERVICE_PAUSE_PENDING = $6; |
312 |
| - SERVICE_PAUSED = $7; |
| 272 | +
|
| 273 | +//Include type definition for Service Control Manager |
| 274 | +#include "incl_ServiceControlManager-definition.pas"; |
| 275 | +
|
313 | 276 |
|
314 | 277 |
|
315 | 278 | var
|
@@ -340,115 +303,8 @@ var
|
340 | 303 | FontStateBuffer: array of string;
|
341 | 304 |
|
342 | 305 |
|
343 |
| -// ####################################################################################### |
344 |
| -// Service control code from http://www.vincenzo.net/isxkb/index.php?title=Service_-_Functions_to_Start%2C_Stop%2C_Install%2C_Remove_a_Service |
345 |
| -function OpenSCManager(lpMachineName, lpDatabaseName: string; dwDesiredAccess :cardinal): HANDLE; |
346 |
| -external 'OpenSCManagerA@advapi32.dll stdcall'; |
347 |
| -
|
348 |
| -function OpenService(hSCManager :HANDLE;lpServiceName: string; dwDesiredAccess :cardinal): HANDLE; |
349 |
| -external 'OpenServiceA@advapi32.dll stdcall'; |
350 |
| -
|
351 |
| -function CloseServiceHandle(hSCObject :HANDLE): boolean; |
352 |
| -external 'CloseServiceHandle@advapi32.dll stdcall'; |
353 |
| -
|
354 |
| -function StartNTService(hService :HANDLE;dwNumServiceArgs : cardinal;lpServiceArgVectors : cardinal) : boolean; |
355 |
| -external 'StartServiceA@advapi32.dll stdcall'; |
356 |
| -
|
357 |
| -function ControlService(hService :HANDLE; dwControl :cardinal;var ServiceStatus :SERVICE_STATUS) : boolean; |
358 |
| -external 'ControlService@advapi32.dll stdcall'; |
359 |
| -
|
360 |
| -function QueryServiceStatus(hService :HANDLE;var ServiceStatus :SERVICE_STATUS) : boolean; |
361 |
| -external 'QueryServiceStatus@advapi32.dll stdcall'; |
362 |
| -
|
363 |
| -function OpenServiceManager() : HANDLE; |
364 |
| -begin |
365 |
| - if UsingWinNT() = true then begin |
366 |
| - Result := OpenSCManager('','ServicesActive',SC_MANAGER_ALL_ACCESS); |
367 |
| - if Result = 0 then |
368 |
| - MsgBox('the servicemanager is not available', mbError, MB_OK) |
369 |
| - end |
370 |
| - else begin |
371 |
| - MsgBox('only nt based systems support services', mbError, MB_OK) |
372 |
| - Result := 0; |
373 |
| - end |
374 |
| -end; |
375 |
| -
|
376 |
| -function IsServiceInstalled(ServiceName: string) : boolean; |
377 |
| -var |
378 |
| - hSCM : HANDLE; |
379 |
| - hService: HANDLE; |
380 |
| -begin |
381 |
| - hSCM := OpenServiceManager(); |
382 |
| - Result := false; |
383 |
| - if hSCM <> 0 then begin |
384 |
| - hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_CONFIG); |
385 |
| - if hService <> 0 then begin |
386 |
| - Result := true; |
387 |
| - CloseServiceHandle(hService) |
388 |
| - end; |
389 |
| - CloseServiceHandle(hSCM) |
390 |
| - end |
391 |
| -end; |
392 |
| -
|
393 |
| -
|
394 |
| -
|
395 |
| -function StartService(ServiceName: string) : boolean; |
396 |
| -var |
397 |
| - hSCM : HANDLE; |
398 |
| - hService: HANDLE; |
399 |
| -begin |
400 |
| - hSCM := OpenServiceManager(); |
401 |
| - Result := false; |
402 |
| - if hSCM <> 0 then begin |
403 |
| - hService := OpenService(hSCM,ServiceName,SERVICE_START); |
404 |
| - if hService <> 0 then begin |
405 |
| - Result := StartNTService(hService,0,0); |
406 |
| - CloseServiceHandle(hService) |
407 |
| - end; |
408 |
| - CloseServiceHandle(hSCM) |
409 |
| - end; |
410 |
| -end; |
411 |
| -
|
412 |
| -function StopService(ServiceName: string) : boolean; |
413 |
| -var |
414 |
| - hSCM : HANDLE; |
415 |
| - hService: HANDLE; |
416 |
| - Status : SERVICE_STATUS; |
417 |
| -begin |
418 |
| - hSCM := OpenServiceManager(); |
419 |
| - Result := false; |
420 |
| - if hSCM <> 0 then begin |
421 |
| - hService := OpenService(hSCM,ServiceName,SERVICE_STOP); |
422 |
| - if hService <> 0 then begin |
423 |
| - Result := ControlService(hService,SERVICE_CONTROL_STOP,Status); |
424 |
| - CloseServiceHandle(hService) |
425 |
| - end; |
426 |
| - CloseServiceHandle(hSCM) |
427 |
| - end; |
428 |
| -end; |
429 |
| -
|
430 |
| -function IsServiceRunning(ServiceName: string) : boolean; |
431 |
| -var |
432 |
| - hSCM : HANDLE; |
433 |
| - hService: HANDLE; |
434 |
| - Status : SERVICE_STATUS; |
435 |
| -begin |
436 |
| - hSCM := OpenServiceManager(); |
437 |
| - Result := false; |
438 |
| - if hSCM <> 0 then begin |
439 |
| - hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_STATUS); |
440 |
| - if hService <> 0 then begin |
441 |
| - if QueryServiceStatus(hService,Status) then begin |
442 |
| - Result :=(Status.dwCurrentState = SERVICE_RUNNING) |
443 |
| - end; |
444 |
| - CloseServiceHandle(hService) |
445 |
| - end; |
446 |
| - CloseServiceHandle(hSCM) |
447 |
| - end |
448 |
| -end; |
449 |
| -
|
450 |
| -// ####################################################################################### |
451 |
| -
|
| 306 | +//Include functions for Service Control Manager |
| 307 | +#include "incl_ServiceControlManager-functions.pas"; |
452 | 308 |
|
453 | 309 |
|
454 | 310 |
|
@@ -655,31 +511,6 @@ end;
|
655 | 511 |
|
656 | 512 |
|
657 | 513 |
|
658 |
| -//Returns TRUE if a service was started |
659 |
| -function StartNTService2(serviceName:string):boolean; |
660 |
| -begin |
661 |
| - if IsServiceInstalled(serviceName) then begin |
662 |
| - if IsServiceRunning(serviceName)=false then begin |
663 |
| - log('Starting service ' + serviceName); |
664 |
| - StartService(serviceName); |
665 |
| - sleep(1500); //give the service some seconds |
666 |
| - result:=true; |
667 |
| - end; |
668 |
| - end; |
669 |
| -end; |
670 |
| -
|
671 |
| -//Stops a service and returns TRUE if it was stopped |
672 |
| -function StopNTService2(serviceName:string):boolean; |
673 |
| -begin |
674 |
| - if IsServiceInstalled(serviceName) then begin |
675 |
| - if IsServiceRunning(serviceName) then begin |
676 |
| - log('Stopping service ' + serviceName); |
677 |
| - StopService(serviceName); |
678 |
| - sleep(1500); |
679 |
| - result:=true; |
680 |
| - end; |
681 |
| - end; |
682 |
| -end; |
683 | 514 |
|
684 | 515 |
|
685 | 516 | //Show a custom prepare to install page in order to give the user output what we are doing
|
|
0 commit comments