• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            兔子的技術(shù)博客

            兔子

               :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              202 Posts :: 0 Stories :: 43 Comments :: 0 Trackbacks

            留言簿(10)

            最新評論

            閱讀排行榜

            評論排行榜

            環(huán)境 VC6.0

            #include "windows.h"

            SERVICE_STATUS          gSvcStatus;  //服務(wù)狀態(tài)

            SERVICE_STATUS_HANDLE   gSvcStatusHandle; //服務(wù)狀態(tài)句柄

            HANDLE                  ghSvcStopEvent = NULL;//服務(wù)停止句柄

            #define SERVER_NAME    TEXT("my_server") //服務(wù)名

            VOID WINAPI Server_main( DWORD, LPTSTR *); //服務(wù)入口點

            void ServerReportEvent(LPTSTR szName,LPTSTR szFunction); //寫Windows日志

            VOID ReportSvcStatus( DWORD, DWORD, DWORD ); //服務(wù)狀態(tài)和SCM交互

            VOID WINAPI SvcCtrlHandler( DWORD );  //SCM回調(diào)函數(shù)

            VOID ServerProgram(DWORD, LPTSTR *); //服務(wù)主程序

            void main()



                SERVICE_TABLE_ENTRY DispatchTable[] =

                {

                    { SERVER_NAME, (LPSERVICE_MAIN_FUNCTION)Server_main },

                    { NULL, NULL }

                };

                

                if (!StartServiceCtrlDispatcher(DispatchTable))

                {

                     ServerReportEvent(SERVER_NAME,TEXT("StartServiceCtrlDispatcher"));

                }

            }

            static VOID WINAPI Server_main(DWORD dwArgc, LPTSTR *lpszArgv )

            {

                // Register the handler function for the service

                gSvcStatusHandle = RegisterServiceCtrlHandler( 

                    SERVER_NAME, 

                    SvcCtrlHandler);

                

                if( !gSvcStatusHandle )

                { 

                   ServerReportEvent(SERVER_NAME,TEXT("RegisterServiceCtrlHandler")); 

                    return

                } 

                

                // These SERVICE_STATUS members remain as set here

                gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; //只有一個單獨的服務(wù)

                gSvcStatus.dwServiceSpecificExitCode = 0;    

                

                // Report initial status to the SCM

                ReportSvcStatus( SERVICE_START_PENDING, NO_ERROR, 3000 );

                

                // Perform service-specific initialization and work.

                ghSvcStopEvent = CreateEvent(

                    NULL,    // default security attributes

                    TRUE,    // manual reset event

                    FALSE,   // not signaled

                    NULL);   // no name

                

                if ( ghSvcStopEvent == NULL)

                {

                    ReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );

                    return;

                }

                

                // Report running status when initialization is complete.

                ReportSvcStatus( SERVICE_RUNNING, NO_ERROR, 0 );

                

                // TO_DO: Perform work until service stops. 

                ServerProgram(dwArgc, lpszArgv); //你需要的操作在此添加代碼

                

                while(1)

                {

                      // Check whether to stop the service.

                  WaitForSingleObject(ghSvcStopEvent, INFINITE);

                  ReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );

                  return;

                }  

            }

            void ServerReportEvent(LPTSTR szName,LPTSTR szFunction) 



                HANDLE hEventSource;

                LPCTSTR lpszStrings[2];

                unsigned int len = sizeof(szFunction);

                TCHAR *Buffer = new TCHAR[len];

                

                hEventSource = RegisterEventSource(NULL, szName);

                

                if( NULL != hEventSource )

                {

                    //StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError());

                    strcpy(Buffer,szFunction);

                    lpszStrings[0] = szName;

                    lpszStrings[1] = Buffer;

                    

                    ReportEvent(hEventSource,        // event log handle

                        EVENTLOG_ERROR_TYPE, // event type

                        0,                   // event category

                        SVC_ERROR,           // event identifier

                        NULL,                // no security identifier

                        2,                   // size of lpszStrings array

                        0,                   // no binary data

                        lpszStrings,         // array of strings

                        NULL);               // no binary data    

                    DeregisterEventSource(hEventSource);

                }

            }

            VOID ReportSvcStatus( DWORD dwCurrentState,

                                 DWORD dwWin32ExitCode,

                                 DWORD dwWaitHint)

            {

                static DWORD dwCheckPoint = 1;

                

                // Fill in the SERVICE_STATUS structure.

                

                gSvcStatus.dwCurrentState = dwCurrentState;

                gSvcStatus.dwWin32ExitCode = dwWin32ExitCode;

                gSvcStatus.dwWaitHint = dwWaitHint;

                

                if (dwCurrentState == SERVICE_START_PENDING)

                    gSvcStatus.dwControlsAccepted = 0;

                else gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;

                

                if ( (dwCurrentState == SERVICE_RUNNING) ||

                    (dwCurrentState == SERVICE_STOPPED) )

                    gSvcStatus.dwCheckPoint = 0;

                else gSvcStatus.dwCheckPoint = dwCheckPoint++;

                

                // Report the status of the service to the SCM.

                SetServiceStatus( gSvcStatusHandle, &gSvcStatus );

            }

            VOID WINAPI SvcCtrlHandler( DWORD dwCtrl )

            {

                // Handle the requested control code. 

              switch(dwCtrl) 

                {  

                case SERVICE_CONTROL_STOP: 

                    ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);

                    

                    // Signal the service to stop.

                    

                    SetEvent(ghSvcStopEvent);

                    

                    return;

                    

                case SERVICE_CONTROL_INTERROGATE: 

                    // Fall through to send current status.

                    break

                    

                default

                    break;

                } 

                ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0);

            }
            轉(zhuǎn)自:http://3140618.blog.163.com/blog/static/745179720109286165959/
            posted on 2013-09-26 15:24 會飛的兔子 閱讀(2868) 評論(0)  編輯 收藏 引用 所屬分類: 系統(tǒng)API,底層技術(shù)
            国产精品久久久亚洲| 亚洲日韩中文无码久久| 久久久精品2019免费观看| 久久精品综合网| 国产精品成人久久久| 久久婷婷色香五月综合激情| 久久久噜噜噜久久| 开心久久婷婷综合中文字幕| 久久精品综合一区二区三区| 欧美久久一区二区三区| 色99久久久久高潮综合影院| 久久毛片一区二区| 亚洲人成伊人成综合网久久久| 亚洲中文字幕久久精品无码喷水 | 久久午夜免费视频| 一级A毛片免费观看久久精品| 久久久久久国产精品无码下载| 欧美成a人片免费看久久| 狠狠色丁香久久婷婷综合_中 | 香蕉aa三级久久毛片| 亚洲精品无码久久久| 亚洲欧洲日产国码无码久久99| 久久99精品久久久久久久久久| 国产成人综合久久综合| 久久精品中文字幕第23页| 三级片免费观看久久| 久久精品国产99久久无毒不卡| 久久99国产精品久久久| 伊人 久久 精品| 久久精品水蜜桃av综合天堂| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品国产乱码久久久久软件| 婷婷久久久亚洲欧洲日产国码AV | 中文字幕精品久久| 久久99国产综合精品| 久久无码人妻精品一区二区三区| 一本色道久久88精品综合| 国产—久久香蕉国产线看观看| 国产精品99久久久精品无码| 国产成人久久777777| 亚洲国产精品无码久久久不卡|