Solved

service application using Delphi 5/6

Posted on 2002-04-04
2
166 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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