finding the status of the service in windows

Discussion in 'Software' started by suresh_rtp, May 26, 2009.

  1. suresh_rtp

    suresh_rtp

    Joined:
    Feb 20, 2009
    Messages:
    4
    Likes Received:
    0
    hi,
    this is the cod that i was written for getting the service status.i have some problem in this code.i am not able to getting the staus of the service.anybody another code help me.


    DWORD ServiceGetStatus(char *sService)
    {
    SC_HANDLE schm;
    SC_HANDLE schs;
    LPSERVICE_STATUS TServiceStatus = NULL;
    DWORD dwStat = -1;
    // connect to the service control manager
    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;
    }
     
    suresh_rtp, May 26, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.