Communiquer avec un Service
Bonjour,
Je cherche à communiquer avec mon Service depuis mon application à l'aide d'un SendMessage.
Le problème est que je ne suis pas sur que le handle que j'obtiens est le bon pour ce genre de pratique, et mon service ne reçoit apparemment pas le message.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| var
NomService : String;
Handle_Service,Handle_SC : SC_Handle; // handle du service
Status_Service : TServiceStatus;
begin
Handle_SC := OpenSCManager(nil,nil,SC_MANAGER_CONNECT );
if Handle_SC = 0 then
case GetLastError of
ERROR_ACCESS_DENIED : Showmessage('The requested access was denied.');
ERROR_DATABASE_DOES_NOT_EXIST : Showmessage('The specified database does not exist.');
ERROR_INVALID_PARAMETER : Showmessage('A specified parameter is invalid.');
end
else
begin
NomService:='MonService';
Handle_Service := OpenService(Handle_SC, PChar(NomService), SERVICE_ALL_ACCESS);
If Handle_Service = 0 then
case GetLastError of
ERROR_ACCESS_DENIED : Showmessage('The handle does not have access to the service.');
ERROR_INVALID_HANDLE : Showmessage('The specified handle is invalid.');
ERROR_INVALID_NAME : Showmessage('The specified service name is invalid.');
ERROR_SERVICE_DOES_NOT_EXIST : Showmessage('The specified service does not exist.');
end
else
begin
QueryServiceStatus(Handle_Service, Status_Service);
Memo1.Lines.Add( IntToStr( Status_Service.dwCurrentState ) );
Memo1.Lines.Add( IntToStr( SendMessage(Handle_Service, WM_MON_MESSAGE, 0, 0 ) ) );
CloseServiceHandle(Handle_Service);
end;
end; |
(c'est un code de test, donc volontairement pas optimisé)
La variable Handle_Service est donc sensé contenir le handle de mon service.
Mais je trouve pour valeur "1409848", que le service soit démarré ou non...
Une idée ?