Solved

How to start as a service on Win 2000 Server

Posted on 2001-09-11
5
143 Views
Last Modified: 2010-04-06
I need to start my Delphi 5 application as a service on Windows 2000 Server.

How can I do this?

Thanks a lot in advance.


AJ
0
Comment
Question by:ajgonzalezm
5 Comments
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 6474859
Listening !!
0
 
LVL 7

Accepted Solution

by:
Motaz earned 50 total points
ID: 6474976
Did you mean you want to write NT services?

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
0
 
LVL 1

Expert Comment

by:Madmarlin
ID: 6475974

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;

            CloseServiceHandle(hdl_Service);
          end;
      CloseServiceHandle(hdl_Manager);
    end;

  Result := hdl_Stat;

  End;

{---------------------------------------------------------}


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..

Madmarlin..  ;?)
0
 

Expert Comment

by:DelFreak
ID: 6478319
Listening...
0
 
LVL 17

Expert Comment

by:geobul
ID: 9296710
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept Motaz's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
Send message from delphi to whatsapp, is it possible? 3 1,446
drawing animated level bar based on numbers 3 97
Graphics32 under Delphi 10.1 Berlin 2 66
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question