Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

services

Status
Not open for further replies.

domkop

Programmer
Aug 19, 2003
22
NL
how do i stop services,
i want to quit some services and start them again later on
 
Found this code on the web and saved it... haven't tried it yet.

This code basically starts/stops the webservice.
Code:
Uses WinSvc;
procedure TForm1.Button1Click(Sender: TObject);
var sc_h, sc_man : SC_HANDLE;
begin
  sc_man := OpenSCManager(nil, nil, SERVICE_START);
  if sc_man = 0 then
    ShowMessage('OpenSCManager' + SysErrorMessage(GetLastError))
  else begin
    sc_h := OpenService(sc_man, 'W3SVC', SERVICE_START);
    if sc_h = 0 then
      ShowMessage('OpenSevice: ' + SysErrorMessage(GetLastError))
    else begin
      StartService(sc_h, 0, PChar(nil^));
      CloseServiceHandle(sc_h);
    end;
    CloseServiceHandle(sc_man);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var sc_h, sc_man : SC_HANDLE;
    sstat: TServiceStatus;
begin
  sc_man := OpenSCManager(nil, nil, SERVICE_START);
  if sc_man = 0 then
    ShowMessage('OpenSCManager' + SysErrorMessage(GetLastError))
  else begin
    sc_h := OpenService(sc_man, 'W3SVC', SERVICE_STOP);
    if sc_h = 0 then
      ShowMessage('OpenSevice: ' + SysErrorMessage(GetLastError))
    else begin
      ControlService(sc_h, SERVICE_CONTROL_STOP, sstat);
      CloseServiceHandle(sc_h);
    end;
    CloseServiceHandle(sc_man);
  end;
end;

Regards and HTH,
JGS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top