我用了一个最简单的方法实现这样的功能
做一个服务,专门启动一个*.bat文件
而在bat里面实现要启动的程序,非常方便(任意添加删除所启动的程序)而且实现也很简单
与你说的
"一双击exe就加入到windows服务中去了,并且自启动 "有相同效果
新建->服务,在代码里实现
procedure TcreateProcessByServ.ServiceStart(Sender: TService;
var Started: Boolean);
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
Started := True;
BatchFileName := ExtractFilePath(ParamStr(0)) + 'a.bat';
//WinExec(PChar(BatchFileName),1);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_SHOWNORMAL;
CreateProcess(nil, PChar(BatchFileName), nil, nil,
False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
ProcessInfo);
end;