我使用向导创建了一个新Windows Service
项目,放置了一些代码,编译它,运行它,/INSTALL
然后我尝试使用它来启动它,net start myservice
但是我遇到了一个service name not found
错误;然后我转到服务中的控制面板,当我尝试开始单击“开始”链接时,显示的对话框窗口无限期地冻结在进度条的 50% 处。
这是我第一次尝试提供服务来更新我正在开发的主系统,并且为了测试,我Timer
每隔一分钟就可以告诉时间。谁能注意到出了什么问题以及为什么会这样?
该DPR
文件具有:
{...}
begin
if not Application.DelayInitialize or Application.Installing then
begin
Application.Initialize;
end;
Application.CreateForm(TZeusUpdateSevice, ZeusUpdateSevice);
Application.Run;
end.
和PAS
文件:
{...}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
ZeusUpdateSevice.Controller(CtrlCode);
end;
function TZeusUpdateSevice.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TZeusUpdateSevice.ServiceAfterInstall(Sender: TService);
var
regEdit : TRegistry;
begin
regEdit := TRegistry.Create(KEY_READ or KEY_WRITE);
try
regEdit.RootKey := HKEY_LOCAL_MACHINE;
if regEdit.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Name,False) then
begin
regEdit.WriteString('Description','Mantém atualizados os arquivos e as credenciais da Plataforma Zeus.');
regEdit.CloseKey;
end;
finally
FreeAndNil(regEdit);
end;
end;
procedure TZeusUpdateSevice.ServiceStart(Sender: TService; var Started: Boolean);
begin
{ executa os processos solicitados pelo sistema }
Timer1.Enabled := True;
while not Terminated do ServiceThread.ProcessRequests(True);
Timer1.Enabled := False;
end;
procedure TZeusUpdateSevice.Timer1Timer(Sender: TObject);
begin
ShowMessage('Now, time is: ' + TimeToStr(Now));
end;