- Click New/NT Service
- You can drop Table, Timers and any non-visual components.
- After producing .exe file do the following:
- write "YourServeiceApp.exe /install"
- write "net start YourServiceName"
- To stop the service and recompile the application:
- write "net stop YourServiceName"
- write "YourServiceApp.exe /uninstall"
Please find 3 functions I use to:
1 Check Service status
2 Stop A Service
3 Start A Service..
Function GetServiceStatus(strMachine, strService : string; var strResult : string) :DWord;
//strResult Not actually needed at this point..<CDS>
var
hdl_Manager, hdl_Service : SC_Handle;
Service_Status : TServiceStatus;
hdl_Stat : DWord;
Begin
hdl_Stat := 1 ;
hdl_Manager := OpenSCManager(Pchar(strMachine), Nil, SC_Manager_Connect);
if hdl_Manager > 0 then
begin
hdl_service := OpenService(hdl_Manager, PChar(strService), SERVICE_QUERY_STATUS);
if hdl_Service > 0 then
begin
if(QueryServiceStatus(hdl_Service, Service_Status)) then
hdl_Stat := Service_Status.dwCurrentState;
function ServiceStop(sMachine, sService: String) : Boolean;
var schm, schs: SC_Handle;
ss: TServiceStatus;
dwChkP: DWord;
begin
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
if (schm>0) then begin
schs := OpenService(schm, PChar(sService), SERVICE_STOP or SERVICE_QUERY_STATUS);
if (schs>0) then
begin
if (ControlService(schs, SERVICE_CONTROL_STOP, ss)) then
if (QueryServiceStatus(schs, ss)) then
while (SERVICE_STOPPED<>ss.dwCurrentState) do
begin
dwChkP := ss.dwCheckPoint;
Sleep(ss.dwWaitHint);
if (not QueryServiceStatus(schs, ss)) then
Break;
if ss.dwCheckPoint <> 0 then
Break;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := SERVICE_STOPPED=ss.dwCurrentState;
end;
function ServiceStart(sMachine, sService: String) : Boolean;
var
schm, schs: SC_Handle;
ss: TServiceStatus;
psTemp: PChar;
dwChkP: DWord;
begin
ss.dwCurrentState := 0;
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
if (schm>0) then
begin
schs := OpenService(schm, PChar(sService), SERVICE_ALL_ACCESS );
if (schs>0) then
begin
psTemp := nil;
if (StartService(schs, 0, psTemp)) then
if (QueryServiceStatus(schs, ss)) then
while (SERVICE_RUNNING<>ss.dwCurrentState) do
begin
dwChkP := ss.dwCheckPoint;
Sleep(ss.dwWaitHint);
if (not QueryServiceStatus(schs, ss)) then
Break;
if ss.dwCheckPoint <> 0 then
Break;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := SERVICE_RUNNING=ss.dwCurrentState;
end;
Simply pass in the Machine Name/Ip address and the NAME of the service. Be sure not to pass in the SERVICENAME and NOT the Display Name. This can be chaecked by right clicking on the service in the Service window (Admin Tools, Services) and selecting to view its properties..
Hope this help. Any problems just let me know and I'll help..
if so then:
- Click New/NT Service
- You can drop Table, Timers and any non-visual components.
- After producing .exe file do the following:
- write "YourServeiceApp.exe /install"
- write "net start YourServiceName"
- To stop the service and recompile the application:
- write "net stop YourServiceName"
- write "YourServiceApp.exe /uninstall"
Motaz