Q
qqqqq
Unregistered / Unconfirmed
GUEST, unregistred user!
如何用DELPHI5写一个NT服务,来打开(和关闭)配置文件里的多个可执行文件。这样我
就不用登陆NT系统自己就可以把我想预先执行的文件给启动,同时也可以我自己关闭
(人工的)。
高手请赐教,我给500分哦,如果不够在多也没有关系拉。我说明我要的是在DELPHI下,
NT 和 WIN2000 ADVANCE SERVER下都可以实现的原代码。
我是这样实现的,我先将可执行文件的路径写在INI文件中,然后用create process
来打开文件的,关闭用的TERMINITE,我在普通APPLICATION中是可以实现的,可是在
APPLICATIONG SERVICE 中就不可以拉。我的原代码在这,请兄弟姐妹们赐招!!
unit zz;
interface
uses
inifiles,Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
Tzzz = class(TService)
procedure ServiceStart(Sender: TService;
var Started: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController;
override;
{ Public declarations }
end;
var
zzz: Tzzz;
lpProcessInformation :array of TProcessInformation;
strcount:integer;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
zzz.Controller(CtrlCode);
end;
function Tzzz.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure Tzzz.ServiceStart(Sender: TService;
var Started: Boolean);
var
pathini:TInifile;
inipath,sCommandLine:string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
i:integer;
begin
//¶ÁÅäÖ÷¾¶Êý
inipath:=ExtractFilePath(paramstr(0))+'exepath.ini';
pathini := TIniFile.Create(inipath);
strcount:=strtoint(pathini.ReadString('exepath','count',''));
pathini.WriteString('exepath','count',inttostr(strcount)+'10000') ;
for i:=1 to strcountdo
begin
sCommandLine:=pathini.ReadString('exepath','path'+inttostr(i),'');
// ?? StartupInfo
FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0);
lpStartupInfo.cb := Sizeof(TStartupInfo);
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_NORMAL;
bCreateProcess := CreateProcess(nil, PChar(sCommandLine),
nil, nil, True, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil, nil, lpStartupInfo, lpProcessInformation[i-1]);
end;
end;
end.
INI文件为EXEPATH。INI
[exepath]
count=3
path1=D:/Program Files/WinZip/WINZIP32.EXE
path2=D:/Program Files/Winamp/winamp.exe
path3=D:/Program Files/Internet Explorer/IEXPLORE.EXE
那位高人可以帮我解决啊,给多多分哦
就不用登陆NT系统自己就可以把我想预先执行的文件给启动,同时也可以我自己关闭
(人工的)。
高手请赐教,我给500分哦,如果不够在多也没有关系拉。我说明我要的是在DELPHI下,
NT 和 WIN2000 ADVANCE SERVER下都可以实现的原代码。
我是这样实现的,我先将可执行文件的路径写在INI文件中,然后用create process
来打开文件的,关闭用的TERMINITE,我在普通APPLICATION中是可以实现的,可是在
APPLICATIONG SERVICE 中就不可以拉。我的原代码在这,请兄弟姐妹们赐招!!
unit zz;
interface
uses
inifiles,Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;
type
Tzzz = class(TService)
procedure ServiceStart(Sender: TService;
var Started: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController;
override;
{ Public declarations }
end;
var
zzz: Tzzz;
lpProcessInformation :array of TProcessInformation;
strcount:integer;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
zzz.Controller(CtrlCode);
end;
function Tzzz.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure Tzzz.ServiceStart(Sender: TService;
var Started: Boolean);
var
pathini:TInifile;
inipath,sCommandLine:string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
i:integer;
begin
//¶ÁÅäÖ÷¾¶Êý
inipath:=ExtractFilePath(paramstr(0))+'exepath.ini';
pathini := TIniFile.Create(inipath);
strcount:=strtoint(pathini.ReadString('exepath','count',''));
pathini.WriteString('exepath','count',inttostr(strcount)+'10000') ;
for i:=1 to strcountdo
begin
sCommandLine:=pathini.ReadString('exepath','path'+inttostr(i),'');
// ?? StartupInfo
FillChar(lpStartupInfo, Sizeof(TStartupInfo), #0);
lpStartupInfo.cb := Sizeof(TStartupInfo);
lpStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
lpStartupInfo.wShowWindow := SW_NORMAL;
bCreateProcess := CreateProcess(nil, PChar(sCommandLine),
nil, nil, True, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
nil, nil, lpStartupInfo, lpProcessInformation[i-1]);
end;
end;
end.
INI文件为EXEPATH。INI
[exepath]
count=3
path1=D:/Program Files/WinZip/WINZIP32.EXE
path2=D:/Program Files/Winamp/winamp.exe
path3=D:/Program Files/Internet Explorer/IEXPLORE.EXE
那位高人可以帮我解决啊,给多多分哦