Sir..I am trying to check whether window service is working properly or not...i wrote code for that ..its working fine for local system ,but when i used this for remote system..its not working...plz help...code for that are as follows..
//Main Unit...
ServiceWatcher := TService.Create();
ShowMessage('Hello ServiceWatcher');
//This is for local system(Which is working fine)
if( ServiceWatcher.ServiceRunning('','CanveraPushOrder' ) )then
begin
ShowMessage('Sevice is running');
end
else begin
ShowMessage('Sevice is not working properly');
end;
if(ServiceWatcher.ServiceStopped('','CanveraPushOrder' ) )then
begin
ShowMessage('Sevice is stoped');
end;
//This is for remote system but its not working
if( ServiceWatcher.ServiceRunning('\\10.30.0.10','OCS inventory service' ) )then
begin
ShowMessage('Sevice is running');
end
else begin
ShowMessage('Sevice is not working properly');
end;
if(ServiceWatcher.ServiceStopped('\\10.30.0.10','OCS inventory service' ) )then
begin
ShowMessage('Sevice is stoped');
end;
//code for TService
unit ServiceStatus;
interface
uses WinSvc,Windows;
type
// The customer class definition
TService = class
private
public
constructor Create;
function ServiceGetStatus(sMachine,sService : string ) : DWord;
function ServiceRunning(sMachine, sService : string ) : boolean;
function ServiceStopped(sMachine, sService : string ) : boolean;
end;
implementation
constructor TService.Create;
begin
end;
function TService.ServiceGetStatus(sMachine,sService : string ) : DWord;
var
schm,schs : SC_Handle;
ss : TServiceStatus;
dwStat : DWord;
begin
//dwStat := -1;
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT);
if(schm > 0)then
begin
schs := OpenService( schm, PChar(sService), SERVICE_QUERY_STATUS);
if(schs > 0)then
begin
if(QueryServiceStatus(schs,ss))then
begin
dwStat := ss.dwCurrentState;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := dwStat;
end;
function TService.ServiceRunning(sMachine, sService : string ) : boolean;
begin
Result := SERVICE_RUNNING = ServiceGetStatus(sMachine, sService );
end;
function TService.ServiceStopped(sMachine, sService : string ) : boolean;
begin
Result := SERVICE_STOPPED = ServiceGetStatus(sMachine, sService );
end;
end.
please check and tell me where i did wrong....y its not working for remort system?