delphi关闭和禁用Windows服务

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)

 

delphi关闭和禁用Windows服务

上一篇:C# 复杂格式XML转实体


下一篇:ArcGIS10.2+Eclipse4.3(Kepler)java开发(一)