delphi Windows 서비스 종료 및 비활성화

2606 단어
function StopServices(const SvrName: string): Boolean;
var
  SCH, SvcSCH: SC_HANDLE;
  SS: TServiceStatus;
begin
  Result := False;
  SCH := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
  if SCH <= 0 then Exit;

  SvcSCH := OpenService(SCH, PChar(SvrName), SERVICE_ALL_ACCESS);
  if SvcSCH <= 0 then Exit;

  try
    Result := ControlService(SvcSCH, SERVICE_CONTROL_STOP, SS);

    if Result then
    begin
      Result := ChangeServiceConfig(SvcSCH, SERVICE_NO_CHANGE, SERVICE_DISABLED,
        SERVICE_NO_CHANGE, nil, nil, nil, nil, nil, nil, nil);
    end;
  finally
    CloseServiceHandle(SCH);
    CloseServiceHandle(SvcSCH);
  end;
end;

호출:
StopServices('WSearch')

좋은 웹페이지 즐겨찾기