• <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>

            Life & Code

            代碼是咒語,我是魔法師

            Win32服務(wù)控制類

            /**
            W32Server.h???
            http://www.shnenglu.com/lovelypig? 橙子
            */
            #ifndef? _CW32SERVER_H
            #define? _CW32SERVER_H
            #include <windows.h>
            #include <stdio.h>

            ?

            class CW32Server
            {
            ?TCHAR??m_szServerName[MAX_PATH];
            ?SC_HANDLE?? m_hService;
            ?SC_HANDLE?? m_hScm;
            ?SERVICE_STATUS ServiceStatus;
            ?BYTE??m_cfgBuf[4096];
            public:

            ?CW32Server(void);
            ?CW32Server(const TCHAR *strServerName);?
            ?BOOL??? Open(const TCHAR *strServerName);??

            ?/**? 返回狀態(tài):
            ??SERVICE_CONTINUE_PENDING The service continue is pending.
            ??SERVICE_PAUSE_PENDING The service pause is pending.
            ??SERVICE_PAUSED The service is paused.
            ??SERVICE_RUNNING The service is running.
            ??SERVICE_START_PENDING The service is starting.
            ??SERVICE_STOP_PENDING The service is stopping.
            ??SERVICE_STOPPED The service is not running.
            ?*/
            ?DWORD?GetState();?????
            ?BOOL??? SetState(DWORD state);
            ?BOOL??? Start();
            ?BOOL??? Stop();

            ?/**
            ??SERVICE_AUTO_START??A service started automatically by the service control manager during system startup.
            ??SERVICE_BOOT_START??A device driver started by the system loader. This value is valid only for driver services.
            ??SERVICE_DEMAND_START?A service started by the service control manager when a process calls the StartService function.
            ??SERVICE_DISABLED??A service that cannot be started. Attempts to start the service result in the error code ERROR_SERVICE_DISABLED.
            ??SERVICE_SYSTEM_START
            ?*/
            ?BOOL??? GetConfig();???//如果返回真,配置狀態(tài)填充在 m_config? 中
            ?SC_HANDLE??? GetHandle();??//需要禁用、啟動服務(wù),使用 ChangeServiceConfig(GetHandle(),...)?? 查看MSDN
            ?~CW32Server(void);

            ?QUERY_SERVICE_CONFIG *m_config;
            };


            #endif


            /**
            W32Server.cpp
            http://www.shnenglu.com/lovelypig? 橙子
            */
            #include ".\w32server.h"
            #include <assert.h>

            CW32Server::CW32Server(void)
            {
            ?memset((char*)&m_szServerName,0,sizeof(TCHAR)*MAX_PATH);
            ?memset((char*)&m_config,0,sizeof(m_config));
            ?m_hService = 0;
            ?m_hScm?? = 0;
            ?m_config = (QUERY_SERVICE_CONFIG*)m_cfgBuf;
            }

            CW32Server::CW32Server(const TCHAR *strServerName)
            {?
            ?assert(strServerName);

            ?CW32Server();
            ?_tcscpy(m_szServerName,strServerName);?

            ?m_hScm=OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE);
            ?if(!m_hScm)
            ?{
            ??return ;
            ?}
            ?m_hService=OpenService(m_hScm,strServerName,SERVICE_ALL_ACCESS);
            ?if(!m_hService)
            ?{
            ??CloseServiceHandle(m_hScm);
            ??m_hScm = NULL;
            ??? }
            }
            CW32Server::~CW32Server(void)
            {
            ?if( m_hScm )
            ?{
            ??CloseServiceHandle(m_hScm);
            ??m_hScm = NULL;
            ?}
            ?if( m_hService )
            ?{
            ??CloseServiceHandle(m_hService);
            ??m_hService = NULL;
            ?}
            }

            BOOL?? CW32Server:: Open(const TCHAR *strServerName)
            {
            ?assert(strServerName);

            ?if( m_hScm )
            ?{
            ??CloseServiceHandle(m_hScm);
            ??m_hScm = NULL;
            ?}
            ?if( m_hService )
            ?{
            ??CloseServiceHandle(m_hService);
            ??m_hService = NULL;
            ?}

            ?_tcscpy(m_szServerName,strServerName);?
            ?m_hScm=OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE);
            ?if(!m_hScm)
            ?{
            ??return FALSE;
            ?}
            ?m_hService=OpenService(m_hScm,strServerName,SERVICE_ALL_ACCESS);
            ?if(!m_hService)
            ?{
            ??CloseServiceHandle(m_hScm);
            ??m_hScm = NULL;
            ??return FALSE;
            ?}
            ?return TRUE;
            }

            DWORD?CW32Server::GetState()
            {?
            ?assert(m_hService);

            ??? if(QueryServiceStatus(m_hService,&ServiceStatus))
            ?{
            ??return ServiceStatus.dwCurrentState;
            ?}
            ?else
            ?{
            ??return 0xffffffff;
            ?}
            }

            BOOL??? CW32Server::SetState(DWORD state)
            {
            ?assert(m_hService);

            ?return ControlService(m_hService,state,&ServiceStatus);
            }

            BOOL??? CW32Server::Start()
            {
            ?assert(m_hService);

            ?return StartService(m_hService,0,NULL);

            }

            BOOL??? CW32Server::Stop()
            {
            ?assert(m_hService);

            ?return ControlService(m_hService,SERVICE_CONTROL_STOP,&ServiceStatus);
            }

            BOOL??? CW32Server::GetConfig()
            {
            ?assert(m_hService);
            ?
            ?DWORD cbBufSize = 4096;
            ?DWORD pcbBytesNeeded = 4096;
            ?return QueryServiceConfig(m_hService,m_config,cbBufSize, &pcbBytesNeeded);
            }

            SC_HANDLE? CW32Server::GetHandle()
            {
            ?assert(m_hService);
            ?return m_hService;
            }

            posted on 2006-04-01 09:55 橙子 閱讀(507) 評論(1)  編輯 收藏 引用 所屬分類: Win32

            評論

            # re: Win32服務(wù)控制類 2007-01-22 16:40 ss5309

            謝謝.  回復(fù)  更多評論   

            <2006年4月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(10)

            隨筆分類

            隨筆檔案

            相冊

            收藏夾

            搜索

            最新評論

            閱讀排行榜

            久久久久国产一级毛片高清板| 一本色综合网久久| 久久夜色精品国产噜噜麻豆| 久久99热这里只有精品国产| 日本免费久久久久久久网站| 久久久久亚洲AV无码网站| 囯产精品久久久久久久久蜜桃| 国产精品乱码久久久久久软件| 国产女人aaa级久久久级| 热re99久久精品国产99热| 狠狠色婷婷综合天天久久丁香| 久久久久久亚洲AV无码专区| 久久人爽人人爽人人片AV| 久久精品国产亚洲AV无码娇色| 成人综合伊人五月婷久久| 久久亚洲国产午夜精品理论片| 亚洲午夜精品久久久久久人妖| 久久国产一区二区| 久久99精品九九九久久婷婷| 久久嫩草影院免费看夜色| 亚洲人成网站999久久久综合| 伊人久久国产免费观看视频| 青青草原综合久久大伊人| 日韩精品久久久久久久电影蜜臀 | 亚洲AV伊人久久青青草原| 日日狠狠久久偷偷色综合免费| 久久人妻少妇嫩草AV蜜桃| 久久久久99精品成人片欧美| 久久久久久久99精品免费观看| 久久中文字幕视频、最近更新| 国产亚洲精品久久久久秋霞| 久久国产精品99精品国产| 国内精品久久久久影院网站| 色妞色综合久久夜夜| 精品国产福利久久久| 久久久久久久综合狠狠综合| 久久久久久久亚洲Av无码| 久久亚洲欧洲国产综合| 99精品久久精品| 欧美亚洲国产精品久久高清| 99久久精品国内|