Solved

service application using Delphi 5/6

Posted on 2002-04-04
2
162 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
2 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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 video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now