finding the service status in windows

Home Forums C Programming finding the service status in windows

This topic contains 0 replies, has 1 voice, and was last updated by  BonnieHeoinm 8 years, 7 months ago.

  • Author
    Posts
  • #2201

    BonnieHeoinm
    Member

    hi,
    this is the that iw as 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.

    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"< }
    }
    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"< if(status == 4)
    std::cout< <"service is running"< return 0;
    }

    thanks & regards
    suresh

You must be logged in to reply to this topic.

0 Shares
Share
+1
Tweet
Share
Stumble