1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

finding the service status in windows

Discussion in 'Win32' started by imported_suresh_rtp, May 26, 2009.

  1. imported_suresh_rtp

    imported_suresh_rtp New Member

    Joined:
    May 4, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    this is the that i was written for gettign the service status.i have some problem in this code.i am not able to getting the staus of the service.anybody have idea plaese help me.

    Code:
    DWORD ServiceGetStatus(char *sService)
    {
        SC_HANDLE schm;
        SC_HANDLE schs;
          LPSERVICE_STATUS TServiceStatus = NULL;
        DWORD dwStat = -1;
        //dwStat = -1;
        // connect to the service control manager 
        //schm = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
        schm = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
        if(schm > 0)
        {
            schs = OpenService(schm,sService,SERVICE_QUERY_STATUS);
    
            if(schs > 0)
            {
                if(QueryServiceStatus(schs,TServiceStatus))
                {
                    dwStat = TServiceStatus->dwCurrentState;
                    CloseServiceHandle(schs);
                    CloseServiceHandle(schm);
                }
                std::cout<<"status is false"<<std::endl;
            }
        }
        return dwStat;
    }
    int main()
    {
        DWORD status = 0;
        const char machine[]="";
        CHAR  Service_Name[32];
        strcpy(Service_Name,"Sundar_Service");
        status = ServiceGetStatus(Service_Name);
        if(status == 1)
            std::cout<<"service stopped"<<std::endl;
        if(status == 4)
            std::cout<<"service is running"<<std::endl;
        return 0;
    }
     
  2. george135

    george135 New Member

    Joined:
    Feb 16, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    See on Adv. Win32 group (Google Groups, comp.os.ms-windows.programmer.win32)
    where it has often been explained
     

Share This Page