Arsip: Listing untuk Stop SQL Server Agent ...

 
user image
more 13 years ago

heriher

Buat pakar dan mbah delphi, gimana listing (kode program) untuk stop SQL Server Agent. Saya perlu untuk copy database eksternal ... hatoer noehoen...
user image
more 13 years ago

DelphiExpert


program test;
uses
  WinSvc;
{sc-----------------------------------------------------------------------
  ServiceStart
  sMachine:
     machine name, ie: \\SERVER
     empty = local machine
  Purpose:
     start service
     return TRUE if successful
-----------------------------------------------------------------------sc}
function ServiceStart(sMachine, sService: String) : Boolean;
var
  schm,
  schs: SC_Handle;
  ss: TServiceStatus;
  psTemp: PChar;
  dwChkP: DWord;
begin
  ss.dwCurrentState := 1; 
  schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
  if (schm>0) then
  begin
    schs := OpenService(schm, PChar(sService), SERVICE_START or
      SERVICE_QUERY_STATUS);
    if (schs>0) then
    begin
      psTemp := nil;
      if (StartService(schs, 0, psTemp)) then
        if (QueryServiceStatus(schs, ss)) then
          while (SERVICE_RUNNING<>ss.dwCurrentState) do
          begin
            dwChkP := ss.dwCheckPoint;
            Sleep(ss.dwWaitHint);
            if (not QueryServiceStatus(schs, ss)) then
              Break;
            if (ss.dwCheckPoint < dwChkP) then
              Break;
          end;
      CloseServiceHandle(schs);
    end;
    CloseServiceHandle(schm);
  end;
  Result := SERVICE_RUNNING=ss.dwCurrentState;
end;

{sc-----------------------------------------------------------------------
  ServiceStop
  Purpose:
   stop a service, parameters as in ServiceStart
-----------------------------------------------------------------------sc}
function ServiceStop(sMachine, sService: String) : Boolean;
var
  schm,
  schs: SC_Handle;
  ss: TServiceStatus;
  dwChkP: DWord;
begin
  schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
  if (schm>0) then
  begin
    schs := OpenService(schm, PChar(sService), SERVICE_STOP or
      SERVICE_QUERY_STATUS);
    if (schs>0) then
    begin
      if (ControlService(schs, SERVICE_CONTROL_STOP, ss)) then
        if (QueryServiceStatus(schs, ss)) then
          while (SERVICE_STOPPED<>ss.dwCurrentState) do
          begin
            dwChkP := ss.dwCheckPoint;
            Sleep(ss.dwWaitHint);
            if (not QueryServiceStatus(schs, ss)) then
              Break;
            if (ss.dwCheckPoint < dwChkP) then
              Break;
          end;
      CloseServiceHandle(schs);
    end;
    CloseServiceHandle(schm);
  end;
  Result := SERVICE_STOPPED=ss.dwCurrentState;
end;

begin
  if (ServiceStart('\\ComputerName', 'alerter')) then
  begin
    // ..
  end;
  // sesuaikan dengan nama SQL Server Agent service
  if (ServiceStop('', 'alerter')) then
  begin
    // ..
  end;
end.
user image
more 13 years ago

heriher

Kalau manggil di program utamanya gimana ? begin if (ServiceStart('\\ComputerName', 'alerter')) then begin ---ini diisi apa ? // .. end; // sesuaikan dengan nama SQL Server Agent service if (ServiceStop('', 'alerter')) then begin // .. --- ini kode programnya gimana ? end ;end. Tolong kasih tau ya.... buat yang tau ...
user image
more 13 years ago

DelphiExpert

lho.. lho.. ya kembali ke sampean maunya apa? aneh :mrgreen:
user image
more 13 years ago

cyber_hecker

huahahah... :D
  if (ServiceStart('\\ComputerName', 'alerter')) then //-> ini udah berfungsi buat hidupin servis
  begin
 
    // ..
  end;
  if (ServiceStop('', 'alerter')) then //-> ini buat mati in servis
  begin
 
    // ..
  end;
jadi kode di dalam bisa kamu isi dengan perintah jika servis MS SQL berhasil dihidupin maka... atau jika servis MS SQL berhasil di mati in maka ...
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com