Solved

service application using Delphi 5/6

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

16 Experts available now in Live!

Get 1:1 Help Now