-1
私はC++ Builder 6で簡単なサービスをしようとしています。ここでは、OnStart、OnStop、OnCreate ...のようなサービスの各イベントを記録していますが、OnExecute、OnStart、 OnStopイベントは記録されません。私は何が欠けていますか?C++ Builder 6でのサービスアプリケーション
OnExecuteイベント、OnStartメソッドとOnStopイベント:サービスの
void __fastcall TServiceDump::ServiceExecute(TService *Sender)
{
doSaveLog("ServiceExecute");
while(!Terminated)
{
ServiceThread->ProcessRequests(true);
}
}
//---------------------------------------------------------------------------
void __fastcall TServiceDump::ServiceStart(TService *Sender, bool &Started)
{
doSaveLog("ServiceStart");
}
//---------------------------------------------------------------------------
void __fastcall TServiceDump::ServiceStop(TService *Sender, bool &Stopped)
{
doSaveLog("ServiceStop");
}
いくつかのより多くのイベント:
void __fastcall TServiceDump::ServiceAfterInstall(TService *Sender)
{
doSaveLog("ServiceAfterInstall");
}
//---------------------------------------------------------------------------
void __fastcall TServiceDump::ServiceAfterUninstall(TService *Sender)
{
doSaveLog("ServiceAfterUninstall");
}
//---------------------------------------------------------------------------
void __fastcall TServiceDump::ServiceBeforeInstall(TService *Sender)
{
doSaveLog("ServiceBeforeInstall");
}
//---------------------------------------------------------------------------
void __fastcall TServiceDump::ServiceBeforeUninstall(TService *Sender)
{
doSaveLog("ServiceBeforeUninstall");
}
ログ機能(偉大な作業):
void __fastcall TServiceDump::doSaveLog(String msg)
{
TStrings* list = new TStringList;
try
{
if(FileExists("txt.log"))
{
list->LoadFromFile("txt.log");
}
list->Add(TimeToStr(Now()) + " : " + msg);
}
catch(Exception& e)
{
list->Add(TimeToStr(Now()) + ": ERROR " + e.Message);
}
list->SaveToFile("txt.log");
list->Free();
}
私はインストールすることができますし、サービスを適切にアンインストールし、開始、停止、一時停止、再起動も行います。
17:14:16 : ServiceCreate
17:14:16 : ServiceBeforeInstall
17:14:16 : ServiceAfterInstall
17:14:17 : ServiceDestroy
私が始めてきたし、それを数回、保存されていないログを停止:
私のログファイルには、インストール後。
アンインストール後に私のログファイル:
17:15:44 : ServiceCreate
17:15:44 : ServiceBeforeUninstall
17:15:44 : ServiceAfterUninstall
17:15:45 : ServiceDestroy