::: µ¨ÆÄÀÌ Tip&Trick :::

µ¨ÆÄÀÌ Tip&Trick ¼º°Ý¿¡ ¸ÂÁö ¾Ê´Â ±¤°í,ºñ¹æ,Áú¹®ÀÇ ±ÛÀº Áï½Ã »èÁ¦Çϸç
³»¿ëÀ» º¹»çÇÏ¿© »ç¿ëÇÒ °æ¿ì ¹Ýµå½Ã À̰÷(http://www.howto.pe.kr)À» Ãâó·Î ¸í½ÃÇÏ¿© ÁÖ¼¼¿ä


Category

  ±è¿µ´ë(2004-07-22 19:51:14, Hit : 6333, Vote : 1566
 http://www.howto.pe.kr
 À©µµ¿ìÁî ¼­ºñ½º ½ÃÀÛ/ÁßÁö Çϱâ

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, WinSvc, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

//
// start service
//
// return TRUE if successful
//
// sMachine:
//   machine name, ie: \SERVER
//   empty = local machine
//
// sService
//   service name, ie: Alerter
//
function ServiceStart(
  sMachine,
  sService : string ) : boolean;
var
  //
  // service control
  // manager handle
  schm,
  //
  // service handle
  schs   : SC_Handle;
  //
  // service status
  ss     : TServiceStatus;
  //
  // temp char pointer
  psTemp : PChar;
  //
  // check point
  dwChkP : DWord;
begin
  ss.dwCurrentState := DWORD(-1);
  
  // connect to the service
  // control manager
  schm := OpenSCManager(
    PChar(sMachine),
    Nil,
    SC_MANAGER_CONNECT);

  // if successful...
  if(schm > 0)then
  begin
    // open a handle to
    // the specified service
    schs := OpenService(
      schm,
      PChar(sService),
      // we want to
      // start the service and
      SERVICE_START or
      // query service status
      SERVICE_QUERY_STATUS);

    // if successful...
    if(schs > 0)then
    begin
      psTemp := Nil;
      if(StartService(
           schs,
           0,
           psTemp))then
      begin
        // check status
        if(QueryServiceStatus(
             schs,
             ss))then
        begin
          while(SERVICE_RUNNING
            <> ss.dwCurrentState)do
          begin
            //
            // dwCheckPoint contains a
            // value that the service
            // increments periodically
            // to report its progress
            // during a lengthy
            // operation.
            //
            // save current value
            //
            dwChkP := ss.dwCheckPoint;

            //
            // wait a bit before
            // checking status again
            //
            // dwWaitHint is the
            // estimated amount of time
            // the calling program
            // should wait before calling
            // QueryServiceStatus() again
            //
            // idle events should be
            // handled here...
            //
            Sleep(ss.dwWaitHint);

            if(not QueryServiceStatus(
                 schs,
                 ss))then
            begin
              // couldn't check status
              // break from the loop
              break;
            end;

            if(ss.dwCheckPoint <
              dwChkP)then
            begin
              // QueryServiceStatus
              // didn't increment
              // dwCheckPoint as it
              // should have.
              // avoid an infinite
              // loop by breaking
              break;
            end;
          end;
        end;
      end;

      // close service handle
      CloseServiceHandle(schs);
    end;

    // close service control
    // manager handle
    CloseServiceHandle(schm);
  end;

  // return TRUE if
  // the service status is running
  Result :=
    SERVICE_RUNNING =
      ss.dwCurrentState;
end;

//
// stop service
//
// return TRUE if successful
//
// sMachine:
//   machine name, ie: \SERVER
//   empty = local machine
//
// sService
//   service name, ie: Alerter
//
function ServiceStop(
  sMachine,
  sService : string ) : boolean;
var
  //
  // service control
  // manager handle
  schm,
  //
  // service handle
  schs   : SC_Handle;
  //
  // service status
  ss     : TServiceStatus;
  //
  // check point
  dwChkP : DWord;
begin
  // connect to the service
  // control manager
  schm := OpenSCManager(
    PChar(sMachine),
    Nil,
    SC_MANAGER_CONNECT);

  // if successful...
  if(schm > 0)then
  begin
    // open a handle to
    // the specified service
    schs := OpenService(
      schm,
      PChar(sService),
      // we want to
      // stop the service and
      SERVICE_STOP or
      // query service status
      SERVICE_QUERY_STATUS);

    // if successful...
    if(schs > 0)then
    begin
      if(ControlService(
           schs,
           SERVICE_CONTROL_STOP,
           ss))then
      begin
        // check status
        if(QueryServiceStatus(
             schs,
             ss))then
        begin
          while(SERVICE_STOPPED
            <> ss.dwCurrentState)do
          begin
            //
            // dwCheckPoint contains a
            // value that the service
            // increments periodically
            // to report its progress
            // during a lengthy
            // operation.
            //
            // save current value
            //
            dwChkP := ss.dwCheckPoint;

            //
            // wait a bit before
            // checking status again
            //
            // dwWaitHint is the
            // estimated amount of time
            // the calling program
            // should wait before calling
            // QueryServiceStatus() again
            //
            // idle events should be
            // handled here...
            //
            Sleep(ss.dwWaitHint);

            if(not QueryServiceStatus(
                 schs,
                 ss))then
            begin
              // couldn't check status
              // break from the loop
              break;
            end;

            if(ss.dwCheckPoint <
              dwChkP)then
            begin
              // QueryServiceStatus
              // didn't increment
              // dwCheckPoint as it
              // should have.
              // avoid an infinite
              // loop by breaking
              break;
            end;
          end;
        end;
      end;

      // close service handle
      CloseServiceHandle(schs);
    end;

    // close service control
    // manager handle
    CloseServiceHandle(schm);
  end;

  // return TRUE if
  // the service status is stopped
  Result :=
    SERVICE_STOPPED =
      ss.dwCurrentState;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // ¼­ºñ½º ½ÃÀÛ Çϱâ(¿©±â¼­´Â DHCP Ŭ¶óÀÌ¾ðÆ®·Î Å×½ºÆ® ÇßÀ½)
  if( ServiceStart(
    '',
    'Dhcp' ) )then
  begin
    ShowMessage('DHCP Client service on the local computer was started');
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  // ¼­ºñ½º ÁßÁö Çϱâ
  if( ServiceStop(
    '',
    'Dhcp' ) )then
  begin
    ShowMessage('DHCP Client service on the local computer was stopped');
  end;
end;

end.





211   [À©µµ¿ìÁî API] ÄÞÆ÷³ÍÆ®ÀÇ Hint ¿¡ ±×¸²(Bitmap) ³Ö±â  ±è¿µ´ë 2003/04/11 5345 1370
210   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] Űº¸µåÀÇ Shift+Tab ÀÌ ´­¸°°Íó·³ ó¸®ÇÏ±â  ±è¿µ´ë 2003/04/14 4878 1318
209   [À©µµ¿ìÁî API] ÆûÀÌ Minimized µÇ¾úÀ»¶§ ±ô¹ÚÀÌ°Ô Çϱâ 2  ±è¿µ´ë 2003/04/14 6165 1329
208   [COM/OLE] ±×¸®µå ÀÚ·á ¿¢¼¿·Î Á»´õ ºü¸£°Ô º¸³»±â  °ø¼ºÈ¯ 2003/04/16 5703 986
207   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] C¿¡¼­ ÇѱÛÀÚ¸£±â  °ø¼ºÈ¯ 2003/04/16 4981 989
206   [COM/OLE] ±âÁ¸ Excel ¹®¼­ ºÒ·¯¿Í¼­ ÆíÁýÈÄ ÀúÀåÇÏ±â  ±è¿µ´ë 2003/04/18 5643 1310
205   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] thread-safe Queue ±¸Çö  ±è¿µ´ë 2003/08/18 6438 1383
204   [¾Ë°í¸®Áò] ¼ýÀÚ¸¦ KB, MB, GB ´ÜÀ§·Î ȯ»êÇÏ±â  ±è¿µ´ë 2003/11/13 5190 1181
203   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] StrToFloatDef  ±è¿µ´ë 2003/11/13 5092 1261
202   [¾Ë°í¸®Áò] ±¸ºÐÀÚ(delimiter)¸¦ »ç¿ëÇÑ ¹®ÀÚ¿­ ÆÄ½Ì(parsing)  ±è¿µ´ë 2003/11/13 5295 1158
201   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] thread-safe Queue¸¦ ÀÌ¿ëÇÑ TLogThread  ±è¿µ´ë 2003/11/18 4958 1156
200   [³×Æ®¿÷/ÀÎÅͳÝ] IOCP(I/O Completion Port) class  ±è¿µ´ë 2003/11/18 11207 896
199   [³×Æ®¿÷/ÀÎÅͳÝ] Winsock WriteFile and Overlapped IO  ±è¿µ´ë 2003/11/18 5539 1242
198   [½Ã½ºÅÛ] À©µµ¿ìÁî ¼­ºñ½º ¸ñ·Ï ±¸ÇÏ±â  ±è¿µ´ë 2004/07/22 4743 1254
197   [½Ã½ºÅÛ] À©µµ¿ìÁî ¼­ºñ½º »óÅ ±¸ÇÏ±â  ±è¿µ´ë 2004/07/22 5170 1295
  [½Ã½ºÅÛ] À©µµ¿ìÁî ¼­ºñ½º ½ÃÀÛ/ÁßÁö ÇÏ±â  ±è¿µ´ë 2004/07/22 6333 1566
195   [½Ã½ºÅÛ] À©µµ¿ìÁî ½Ã½ºÅÛÀÇ ½ºÅ©·Ñ¹Ù µÎ²² ¹Ù²Ù±â  ±è¿µ´ë 2004/07/24 5799 1435
194   [½Ã½ºÅÛ] ¸¶¿ì½º ¾Æ·¡ÀÇ À©µµ¿ì ÇÚµé ±¸ÇÏ±â  ±è¿µ´ë 2004/07/24 13358 4125
193   [½Ã½ºÅÛ] ³» ÇÁ·Î±×·¥ÀÇ ½ÇÇà ¿ì¼±¼øÀÇ ¹Ù²Ù±â  ±è¿µ´ë 2004/07/24 5242 1404
192   [À©µµ¿ìÁî API] ³» ÇÁ·Î±×·¥ÀÇ È­¸éÀ» °¡¸®´Â ÇÁ·Î±×·¥ ¸®½ºÆ®  ±è¿µ´ë 2004/07/24 4706 1219
191   [À©µµ¿ìÁî API] Taskbar ÀÇ Æ¯Á¤ À§Ä¡¿¡ popup ¸Þ´º ¶ç¿ì±â  ±è¿µ´ë 2004/07/24 4722 1223
190   [À©µµ¿ìÁî API] Taskbar ÀÇ À§Ä¡ ÃßÀûÇÏ±â  ±è¿µ´ë 2004/07/24 4238 1084
189   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] À©µµ¿ìÁî"½ÃÀÛ" ¹öưÀ§¿¡ ±Û¾¾ ¾²±â  ±è¿µ´ë 2004/07/24 4279 1164
188   [½Ã½ºÅÛ] Á¦¾îÆÇÀÇ ¸ðµç applet Á¤º¸ ±¸ÇÏ±â  ±è¿µ´ë 2004/07/24 4563 1148
187   [À©µµ¿ìÁî API] ¹Ù·Î Á÷Àü¿¡ active µÇ¾ú´ø À©µµ¿ì¿Í ÄÜÆ®·Ñ ±¸ÇÏ±â  ±è¿µ´ë 2004/07/24 4772 1189
186   [À©µµ¿ìÁî API] Áö¿øÇϴ Űº¸µå ÀÔ·Â ¾ð¾î ±¸ÇÏ°í º¯°æÇÏ±â  ±è¿µ´ë 2004/07/24 4857 1287
185   [À©µµ¿ìÁî API] ÇöÀç Űº¸µå ÀÔ·Â ¾ð¾î ±¸ÇÏ±â  ±è¿µ´ë 2004/07/24 5136 1379
184   [COM/OLE] À©µµ¿ìÁî "ÀÛ¾÷ Ç¥½ÃÁÙ ¹× ½ÃÀÛ ¸Þ´º µî·Ï Á¤º¸" È­¸é  ±è¿µ´ë 2004/07/25 6177 1645
183   [COM/OLE] À©µµ¿ìÁî "ÀÎÅÍ³Ý µî·Ï Á¤º¸" È­¸é  ±è¿µ´ë 2004/07/25 4354 1341
182   [COM/OLE] À©µµ¿ìÁî "³¯Â¥/½Ã°£ µî·Ï Á¤º¸" È­¸é  ±è¿µ´ë 2004/07/25 6485 1663
181   [COM/OLE] À©µµ¿ìÁî "°Ë»ö: ÆÄÀÏ ¶Ç´Â Æú´õ" È­¸é  ±è¿µ´ë 2004/07/25 5073 1406
180   [COM/OLE] À©µµ¿ìÁî "½Ã½ºÅÛ Á¾·á" È­¸é  ±è¿µ´ë 2004/07/25 4676 1319
179   [COM/OLE] À©µµ¿ìÁî "¸ðµç âÀ» ÃÖ¼ÒÈ­"  ±è¿µ´ë 2004/07/25 6335 1728
178   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TList ¸¦ ÀÌ¿ëÇÑ stack ±¸Á¶ ±¸Çö  ±è¿µ´ë 2004/07/25 4497 1176
177   [À©µµ¿ìÁî API] Æû¿¡ ¾Ö´Ï¸ÞÀÌ¼Ç È¿°ú ÁÖ±â  ±è¿µ´ë 2004/07/25 4812 1256
176   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¸ð¼­¸®°¡ µÕ±Ù(rounded ends) TMemo ¸¸µé±â  ±è¿µ´ë 2004/07/25 4781 1195
175   [½Ã½ºÅÛ] ·ÎÄà °¡»ó µå¶óÀ̹ö(substitution device) ¸¸µé°í Á¦°ÅÇÏ±â  ±è¿µ´ë 2004/07/25 8289 1370
174   [³×Æ®¿÷/ÀÎÅͳÝ] ³×Æ®¿öÅ© µå¶óÀÌºê ¿¬°á È­¸é ¶ç¿ì±â  ±è¿µ´ë 2004/07/26 6067 1619
173   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TProgressbar ÀÇ »ö»ó ¹Ù²Ù±â  ±è¿µ´ë 2004/07/26 4716 1248
172   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TTrewView, TListView ¸¦ À̹ÌÁö·Î ÀúÀåÇÏ±â  ±è¿µ´ë 2004/07/26 4466 972

[ÀÌÀü 10°³] [1]..[11][12][13][14][15][16][17][18][19] 20 ..[25] [´ÙÀ½ 10°³]
 

Copyright 1999-2023 Zeroboard / skin by zero