掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DelphiのWindowsサービスのDescriptionの設定方法について (ID:148354)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ちなみにこんなTServiceのヘルパを作って使ってます。参考まで。 unit UServiceHelper; interface uses Winapi.Windows, Winapi.WinSvc, System.SysUtils, Vcl.SvcMgr; type TServiceHelper = class helper for TService public // Set service description (call this function in TService.AfterInstall event) procedure SetServiceDescription(const Description: String); // Set service failure actions procedure SetServiceFailureActions(const Actions: SERVICE_FAILURE_ACTIONS); end; implementation procedure TServiceHelper.SetServiceDescription(const Description: String); var SvcMgr: SC_HANDLE; Svc: SC_HANDLE; ServiceDescr: SERVICE_DESCRIPTION; begin { Open service control manager } SvcMgr := OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS); if SvcMgr = 0 then begin RaiseLastOSError; end; try { Open service } Svc := OpenService(SvcMgr,PChar(Self.Name),STANDARD_RIGHTS_REQUIRED or SERVICE_CHANGE_CONFIG); if Svc = 0 then begin RaiseLastOSError; end; try { Set service description } ServiceDescr.lpDescription := PChar(Description); if ChangeServiceConfig2(Svc,SERVICE_CONFIG_DESCRIPTION,@ServiceDescr) = False then begin RaiseLastOSError; end; finally { Close service handle } CloseServiceHandle(Svc); end; finally { Close service control manager handle } CloseServiceHandle(SvcMgr); end; end; procedure TServiceHelper.SetServiceFailureActions(const Actions: SERVICE_FAILURE_ACTIONS); var SvcMgr: SC_HANDLE; Svc: SC_HANDLE; Access: DWORD; I: Integer; P: LPSC_ACTION; begin Access := STANDARD_RIGHTS_REQUIRED or SERVICE_CHANGE_CONFIG; { Check actions } P := Actions.lpsaActions; if P <> nil then begin for I := 1 to Actions.cActions do // FI:W528 begin if P^.&Type = SC_ACTION_REBOOT then begin Access := Access or SERVICE_START; end; Inc(P); end; end; { Open service control manager } SvcMgr := OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS); if SvcMgr = 0 then begin RaiseLastOSError; end; try { Open service } Svc := OpenService(SvcMgr,PChar(Self.Name), Access); if Svc = 0 then begin RaiseLastOSError; end; try { Set service failure actions } if ChangeServiceConfig2(Svc,SERVICE_CONFIG_FAILURE_ACTIONS,@Actions) = False then begin RaiseLastOSError; end; finally { Close service handle } CloseServiceHandle(Svc); end; finally { Close service control manager handle } CloseServiceHandle(SvcMgr); end; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.