Solved

service application using Delphi 5/6

Posted on 2002-04-04
2
174 Views
Last Modified: 2011-12-10
Does anyone have an example of a Service Application using Delphi 5 or 6? I've created one that I can use which basically calls the program I want to control via Shell Execute but the Start and Stop options are useless. I would like to be able to spawn a new process when Start is pressed and kill the same process when Stop is pressed.
0
Comment
Question by:fussell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 6918669
hi,
> but the Start and Stop options are useless

im guessing you didnt set interactive to true ,for example the code below wouldnt work if the interactive property is not set to true,if you set it to true it works fine and starts/stops notepad on the servicestart/servicestop events :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

type
  TService2 = class(TService)
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  Service2: TService2;

implementation

{$R *.DFM}

uses shellapi;

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  Service2.Controller(CtrlCode);
end;

function TService2.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TService2.ServiceStart(Sender: TService; var Started: Boolean);
begin
ShellExecute(0,'open','notepad',nil,nil,SW_SHOWNORMAL);
end;

procedure TService2.ServiceStop(Sender: TService; var Stopped: Boolean);
var
np : Thandle;
begin
np := FindWindow('Notepad',nil);
If np <> 0 Then
PostMessage(np, WM_CLOSE,0,0);
end;

end.
0
 

Author Comment

by:fussell
ID: 6918710
I had Interacvtive set to true and everything worked fine, however my comment about the buttons being useless may have been overstated. The program started when start was pressed but by using ShellExecute, I was not sure how to stop it. Your example, however, shows me. Thanks.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

615 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