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
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John D

    Windows Explorer Status Bar ?

    John D, Aug 25, 2003, in forum: Computer Support
    Replies:
    2
    Views:
    4,673
    John D
    Aug 25, 2003
  2. fred
    Replies:
    4
    Views:
    495
    ACDeag
    Apr 6, 2006
  3. satlal
    Replies:
    3
    Views:
    1,383
    satlal
    Sep 6, 2005
  4. Leesa_Tay@softhome.net

    Finding Server... Finding Host.... enough already!!!

    Leesa_Tay@softhome.net, Jan 20, 2006, in forum: Computer Support
    Replies:
    2
    Views:
    606
  5. AnonymusProphet@gmail.com

    help finding my service pack 2 files

    AnonymusProphet@gmail.com, Nov 4, 2006, in forum: Computer Support
    Replies:
    3
    Views:
    2,166
    Pennywise@DerryMaine.Gov
    Nov 5, 2006
Loading...

Share This Page