Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Service monitoring (https://www.delphipraxis.net/178881-service-monitoring.html)

WojTec 2. Feb 2014 14:59

Service monitoring
 
I need to know what happening with specified service at runtime to take actions when it state is changed (stopped, deleted, etc.). I tried, but without success, here is what I have:

Delphi-Quellcode:
procedure SvcNotifyCallback(pvParameter: Pointer);
begin

end;

procedure TForm1.FormCreate(Sender: TObject);
var
  hSvcMan, hSvc: Cardinal;
  Buffer: PSERVICE_NOTIFY;
begin
  hSvcMan := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);

  GetMem(Buffer, SizeOf(PSERVICE_NOTIFYW));

  Buffer^.dwVersion := SERVICE_NOTIFY_STATUS_CHANGE;
  Buffer^.pfnNotifyCallback := @SvcNotifyCallback;
  Buffer.pContext := Pointer(nil);

  hSvc := OpenService(hSvcMan, 'UPS', SC_MANAGER_CONNECT);
  NotifyServiceStatusChange(hSvc, SERVICE_NOTIFY_CREATED or SERVICE_NOTIFY_DELETED, Buffer);
end;
This raises external exception. How to trace service, please?


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz