Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

service application using Delphi 5/6

Posted on 2002-04-04
2
Medium Priority
?
179 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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

824 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