-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDMUn.pas
65 lines (54 loc) · 1.35 KB
/
DMUn.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
unit DMUn;
interface
uses
Winapi.Windows, SysUtils, Vcl.SvcMgr,Classes,variants,ServiceParameters;
type
TDM = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
{ Private declarations }
Fpi: TProcessInformation;
Fsi: TStartupInfo;
FExecutableFile,FExecutableDir: string;
FCreateOk: boolean;
public
{ Public declarations }
procedure StartNode;
procedure StopNode;
end;
var
DM: TDM;
implementation
{$R *.dfm}
{ TAgentDM }
procedure TDM.DataModuleCreate(Sender: TObject);
begin
StartNode;
end;
procedure TDM.DataModuleDestroy(Sender: TObject);
begin
StopNode;
end;
procedure TDM.StartNode;
begin
FCreateOk:=false;
fExecutableFile:=ExtractFileDir(ParamStr(0))+'\'+AppName;
if not FileExists(fExecutableFile) then raise Exception.Create(fExecutableFile+' - Not found');
FExecutableDir:=ExtractFileDir(ParamStr(0));
FillMemory( @fsi, sizeof( fsi ), 0 );
fsi.cb := sizeof( fsi );
FCreateOk:=CreateProcess(Nil, PChar( fExecutableFile ),
Nil, Nil, False, CREATE_NO_WINDOW,
Nil, Pchar(FExecutableDir), fsi, fpi);
end;
procedure TDM.StopNode;
begin
if FCreateOk then
begin
TerminateProcess(Fpi.hProcess, 0);
CloseHandle(Fpi.hProcess);
CloseHandle(Fpi.hThread);
end;
end;
end.