線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2745
推到 Plurk!
推到 Facebook!

对Service的一些研究~使普通exe项目和Serivce并用的方法.

 
jbmaster
一般會員


發表:3
回覆:5
積分:1
註冊:2005-08-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-10-29 15:33:56 IP:222.66.xxx.xxx 未訂閱
继 careychen 大的 自動安裝、自動執行的 Service (含 D7 和 D2007 的 Source Code ) 后的研究....

在此感谢careychen大的总结.

下面是对Service的一些研究,使普通exe项目和Serivce并用的方法.


[code delphi]
program ServiceExe;
uses
Forms,
SvcMgr,
RdServiceMainUnit in 'RdServiceMainUnit.pas' {ServiceExe: TService},
RdFormMainUnit in 'RdFormMainUnit.pas' {frmServiceExe};
{$R *.RES}
begin
if ParamCount <> 0 then
begin
SvcMgr.Application.Initialize;
SvcMgr.Application.CreateForm(TServiceExe, ServiceExe);
SvcMgr.Application.Run;
end
else
begin
Forms.Application.Initialize;
Forms.Application.CreateForm(TfrmServiceExe, frmServiceExe);
Forms.Application.Run;
end;
end.
[/code]

关键是让2个Application并存.根据启动方式来选择.

关于Service的研究还在继续,欢迎各位大大探讨.
------
要学的东西太多~
編輯記錄
jbmaster 重新編輯於 2008-10-29 15:36:18, 註解 無‧
careychen
尊榮會員


發表:41
回覆:580
積分:959
註冊:2004-03-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-10-29 16:26:51 IP:60.248.xxx.xxx 訂閱
棒~~~!,過一陣子較有空時會一起跟您研究研究~~,感恩~~~!

===================引 用 jbmaster 文 章===================
careychen 大的 自動安裝、自動執行的 Service (含 D7 和 D2007 的 Source Code ) 后的研究....

在此感谢careychen大的总结.

下面是对Service的一些研究,使普通exe项目和Serivce并用的方法.


[code delphi]
program ServiceExe;
uses
Forms,
SvcMgr,
RdServiceMainUnit in 'RdServiceMainUnit.pas' {ServiceExe: TService},
RdFormMainUnit in 'RdFormMainUnit.pas' {frmServiceExe};
{$R *.RES}
begin
if ParamCount <> 0 then
begin
SvcMgr.Application.Initialize;
SvcMgr.Application.CreateForm(TServiceExe, ServiceExe);
SvcMgr.Application.Run;
end
else
begin
Forms.Application.Initialize;
Forms.Application.CreateForm(TfrmServiceExe, frmServiceExe);
Forms.Application.Run;
end;
end.
[/code]

关键是让2个Application并存.根据启动方式来选择.

关于Service的研究还在继续,欢迎各位大大探讨.
------
價值的展現,來自於你用哪一個角度來看待它!!
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-10-29 18:49:55 IP:59.125.xxx.xxx 訂閱
如果不是掛在 Windows service 下,就不能算是真正的 service 喔!

===================引 用 jbmaster 文 章===================
careychen 大的 自動安裝、自動執行的 Service (含 D7 和 D2007 的 Source Code ) 后的研究....

在此感谢careychen大的总结.

下面是对Service的一些研究,使普通exe项目和Serivce并用的方法.


[code delphi]
program ServiceExe;
uses
Forms,
SvcMgr,
RdServiceMainUnit in 'RdServiceMainUnit.pas' {ServiceExe: TService},
RdFormMainUnit in 'RdFormMainUnit.pas' {frmServiceExe};
{$R *.RES}
begin
if ParamCount <> 0 then
begin
SvcMgr.Application.Initialize;
SvcMgr.Application.CreateForm(TServiceExe, ServiceExe);
SvcMgr.Application.Run;
end
else
begin
Forms.Application.Initialize;
Forms.Application.CreateForm(TfrmServiceExe, frmServiceExe);
Forms.Application.Run;
end;
end.
[/code]

关键是让2个Application并存.根据启动方式来选择.

关于Service的研究还在继续,欢迎各位大大探讨.
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-10-30 08:12:42 IP:61.220.xxx.xxx 訂閱
拜讀一下 
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
honghs
一般會員


發表:0
回覆:1
積分:0
註冊:2008-11-19

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-11-19 16:27:05 IP:220.174.xxx.xxx 未訂閱
borland 自带的例子中就有一个啦。
C:\Program Files\Borland\Delphi7\Source\VclScktSrvr.dpr
{ }
{ Copyright (c) 1997,99 Inprise Corporation }
{ }
{*******************************************************}
program ScktSrvr;
uses
SvcMgr, Forms, Windows, SysUtils, WinSvc, ScktCnst,
ScktMain in 'ScktMain.pas' {SocketForm};
{$R *.RES}
function Installing: Boolean;
begin
Result := FindCmdLineSwitch('INSTALL',['-','\','/'], True) or
FindCmdLineSwitch('UNINSTALL',['-','\','/'], True);
end;
function StartService: Boolean;
var
Mgr, Svc: Integer;
UserName, ServiceStartName: string;
Config: Pointer;
Size: DWord;
begin
Result := False;
Mgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if Mgr <> 0 then
begin
Svc := OpenService(Mgr, PChar(SServiceName), SERVICE_ALL_ACCESS);
Result := Svc <> 0;
if Result then
begin
QueryServiceConfig(Svc, nil, 0, Size);
Config := AllocMem(Size);
try
QueryServiceConfig(Svc, Config, Size, Size);
ServiceStartName := PQueryServiceConfig(Config)^.lpServiceStartName;
if CompareText(ServiceStartName, 'LocalSystem') = 0 then
ServiceStartName := 'SYSTEM';
finally
Dispose(Config);
end;
CloseServiceHandle(Svc);
end;
CloseServiceHandle(Mgr);
end;
if Result then
begin
Size := 256;
SetLength(UserName, Size);
GetUserName(PChar(UserName), Size);
SetLength(UserName, StrLen(PChar(UserName)));
Result := CompareText(UserName, ServiceStartName) = 0;
end;
end;
begin
if not Installing then
begin
CreateMutex(nil, True, 'SCKTSRVR');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
MessageBox(0, PChar(SAlreadyRunning), SApplicationName, MB_ICONERROR);
Halt;
end;
end;
if Installing or StartService then
begin
SvcMgr.Application.Initialize;
SocketService := TSocketService.CreateNew(SvcMgr.Application, 0);
SvcMgr.Application.CreateForm(TSocketForm, SocketForm);
SvcMgr.Application.Run;
end else
begin
Forms.Application.ShowMainForm := False;
Forms.Application.Initialize;
Forms.Application.CreateForm(TSocketForm, SocketForm);
SocketForm.Initialize(False);
Forms.Application.Run;
end;
end.
系統時間:2024-05-14 13:40:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!