I am creating a Windows Service Application with Delphi and I have a big problem:
The service runs, connects to a server via Winsock.. The server, when the client connects send a text to the client(the service) and then the client reads and execute and action. RIGHT AFTER this action is done, the service STOPs..
What I want is: Even when the Client Winsock receive the data and make the action, I would like the service to keep RUNNING and the WINSOCK LISTENING.
I have tested if the Client Winsock can receive data if the service is stopped, but cant.
This is my code for the SERVICE.pas:
unit WebLauncher;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ScktComp, Registry, ShellApi, DSiWin32;
type
TiGunBoundWebLauncher = class(TService)
WebLauncherConector: TClientSocket;
procedure ServiceExecute(Sender: TService);
procedure WebLauncherConectorError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure WebLauncherConectorRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
iGunBoundWebLauncher: TiGunBoundWebLauncher;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
iGunBoundWebLauncher.Controller(CtrlCode);
end;
function TiGunBoundWebLauncher.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TiGunBoundWebLauncher.ServiceExecute(Sender: TService);
begin
WebLauncherConector.Active := True;
ServiceThread.ProcessRequests(False);
end;
procedure TiGunBoundWebLauncher.WebLauncherConectorError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
var error: integer;
begin
error := ErrorCode; {prevent exception from being thrown}
ErrorCode := 0;
if error = 10053 then begin
end;
end;
procedure TiGunBoundWebLauncher.WebLauncherConectorRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Data: string;
GunBoundPath: string;
handle: HWND;
begin
Data := Socket.ReceiveText;
If Pos('Launch', Data) > 0 then begin
GunBoundPath := DSiReadRegistry('\Software\IGunBound\Seasson2',
'Location', '', HKEY_LOCAL_MACHINE, KEY_QUERY_VALUE OR KEY_WOW64_64KEY);
ShellExecute(handle,'open',PChar(GunBoundPath + '\Launcher.exe'), '', PChar(GunBoundPath), SW_SHOWNORMAL);
end;
end;
end.