Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [help]detect the status of iis server

[help]detect the status of iis server

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasesysadminwindows-adminhelp
15 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R rahuljin

    i dont know. i want to this project but i dont know much about it. i come to know that socket programming will be used for this project. actually i am totally new to windows programming but i have to summit this project soon or i will in big trouble. i am trying my best to learn it but time is less, work is more. i will learn windows programming in detail after this project because then i will have more time.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #4

    rahuljin wrote:

    i will learn windows programming in detail after this project because then i will have more time.

    Famous last words. :rolleyes:

    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    R 1 Reply Last reply
    0
    • D David Crow

      rahuljin wrote:

      i will learn windows programming in detail after this project because then i will have more time.

      Famous last words. :rolleyes:

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      R Offline
      R Offline
      rahuljin
      wrote on last edited by
      #5

      really, i know basic of c, c++, java, html\xhtml, vb, etc. this is the frist time i am doing the advance level programming. i want to learn asp .net but not know.

      D 1 Reply Last reply
      0
      • R rahuljin

        really, i know basic of c, c++, java, html\xhtml, vb, etc. this is the frist time i am doing the advance level programming. i want to learn asp .net but not know.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #6

        rahuljin wrote:

        this is the frist time i am doing the advance level programming.

        It's not really an advanced topic as much as it is a specialized topic. See here for an idea.

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        R 1 Reply Last reply
        0
        • D David Crow

          rahuljin wrote:

          this is the frist time i am doing the advance level programming.

          It's not really an advanced topic as much as it is a specialized topic. See here for an idea.

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          R Offline
          R Offline
          rahuljin
          wrote on last edited by
          #7

          thanks for the link. i have tried to write some code but it is not working. can u find the mistake i am making ? i want to find the status of the service "W3SVC", and when it is running, the program should print "Found" ---- #ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <assert.h> #include <windows.h> #include <lm.h> #include <tchar.h> #include <wchar.h> int wmain(int argc, wchar_t * argv[]) { LPSERVER_INFO_101 pBuf = NULL; LPSERVER_INFO_101 pTmpBuf; DWORD dwLevel = 101; DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH; DWORD dwEntriesRead = 0; DWORD dwTotalEntries = 0; DWORD dwTotalCount = 0; DWORD dwServerType = SV_TYPE_SERVER; // all servers DWORD dwResumeHandle = 0; NET_API_STATUS nStatus; LPTSTR pszServerName = NULL; LPTSTR pszDomainName = NULL; DWORD i; if (argc > 2) { fwprintf(stderr, L"Usage: %s [DomainName]\n", argv[0]); exit(1); } // The request is not for the primary domain. // if (argc == 2) pszDomainName = argv[1]; // // Call the NetServerEnum function to retrieve information // for all servers, specifying information level 101. // nStatus = NetServerEnum((LPCWSTR) pszServerName, dwLevel, (LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, dwServerType, (LPCWSTR) pszDomainName, &dwResumeHandle); // // If the call succeeds, // if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) { if ((pTmpBuf = pBuf) != NULL) { // // Loop through the entries and // print the data for all server types. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { fprintf(stderr, "An access violation has occurred\n"); break; } printf("\tPlatform: %d\n", pTmpBuf->sv101_platform_id); wprintf(L"\tName: %s\n", pTmpBuf->sv101_name); printf("\tVersion: %d.%d\n", pTmpBuf->sv101_version_major, pTmpBu

          D 1 Reply Last reply
          0
          • R rahuljin

            thanks for the link. i have tried to write some code but it is not working. can u find the mistake i am making ? i want to find the status of the service "W3SVC", and when it is running, the program should print "Found" ---- #ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <assert.h> #include <windows.h> #include <lm.h> #include <tchar.h> #include <wchar.h> int wmain(int argc, wchar_t * argv[]) { LPSERVER_INFO_101 pBuf = NULL; LPSERVER_INFO_101 pTmpBuf; DWORD dwLevel = 101; DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH; DWORD dwEntriesRead = 0; DWORD dwTotalEntries = 0; DWORD dwTotalCount = 0; DWORD dwServerType = SV_TYPE_SERVER; // all servers DWORD dwResumeHandle = 0; NET_API_STATUS nStatus; LPTSTR pszServerName = NULL; LPTSTR pszDomainName = NULL; DWORD i; if (argc > 2) { fwprintf(stderr, L"Usage: %s [DomainName]\n", argv[0]); exit(1); } // The request is not for the primary domain. // if (argc == 2) pszDomainName = argv[1]; // // Call the NetServerEnum function to retrieve information // for all servers, specifying information level 101. // nStatus = NetServerEnum((LPCWSTR) pszServerName, dwLevel, (LPBYTE *) & pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, dwServerType, (LPCWSTR) pszDomainName, &dwResumeHandle); // // If the call succeeds, // if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) { if ((pTmpBuf = pBuf) != NULL) { // // Loop through the entries and // print the data for all server types. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { fprintf(stderr, "An access violation has occurred\n"); break; } printf("\tPlatform: %d\n", pTmpBuf->sv101_platform_id); wprintf(L"\tName: %s\n", pTmpBuf->sv101_name); printf("\tVersion: %d.%d\n", pTmpBuf->sv101_version_major, pTmpBu

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #8

            rahuljin wrote:

            if ((QueryServiceStatus(hService, &ss) == SERVICE_RUNNING)||(QueryServiceStatus(hService, &ss) == SERVICE_START_PENDING)) printf("Found");

            Should be:

            if (QueryServiceStatus(hService, &ss) != FALSE)
            {
            if (ss.dwCurrentState == SERVICE_RUNNING || ss.dwCurrentState == SERVICE_START_PENDING)
            printf("Found");
            }

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            R 1 Reply Last reply
            0
            • D David Crow

              rahuljin wrote:

              if ((QueryServiceStatus(hService, &ss) == SERVICE_RUNNING)||(QueryServiceStatus(hService, &ss) == SERVICE_START_PENDING)) printf("Found");

              Should be:

              if (QueryServiceStatus(hService, &ss) != FALSE)
              {
              if (ss.dwCurrentState == SERVICE_RUNNING || ss.dwCurrentState == SERVICE_START_PENDING)
              printf("Found");
              }

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              R Offline
              R Offline
              rahuljin
              wrote on last edited by
              #9

              thanks, it is working now. i will bother u soon if i stuck in something. one more thing i want to ask. currently i have only one computer so no network. will this program work on a network of computers too ? i cant check myself. suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ? also, if i have the ip address of the server then how to use it in this program ? thanks again :thumbsup: rahul update : when i make a try to make a array of processes like this -------

              wchar_t selPro[] = { _T("W3SVC"), _T("Iisadmin")};

              SC_HANDLE hService = OpenService(hSCM, selPro[j], SERVICE_QUERY_STATUS);

              where j is for "for" lool (0,1). when i compile this code, compiling completes without any error and when i try to run it, it crashes. if i pass without array, it works fine. please guide me

              modified on Saturday, June 13, 2009 5:05 PM

              D 1 Reply Last reply
              0
              • R rahuljin

                thanks, it is working now. i will bother u soon if i stuck in something. one more thing i want to ask. currently i have only one computer so no network. will this program work on a network of computers too ? i cant check myself. suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ? also, if i have the ip address of the server then how to use it in this program ? thanks again :thumbsup: rahul update : when i make a try to make a array of processes like this -------

                wchar_t selPro[] = { _T("W3SVC"), _T("Iisadmin")};

                SC_HANDLE hService = OpenService(hSCM, selPro[j], SERVICE_QUERY_STATUS);

                where j is for "for" lool (0,1). when i compile this code, compiling completes without any error and when i try to run it, it crashes. if i pass without array, it works fine. please guide me

                modified on Saturday, June 13, 2009 5:05 PM

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #10

                rahuljin wrote:

                will this program work on a network of computers too ?

                That's what NetServerEnum() is for.

                rahuljin wrote:

                suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ?

                First, did you try it? Second, did you check MSDN to see how OpenSCManager() handles its first argument?

                rahuljin wrote:

                also, if i have the ip address of the server then how to use it in this program ?

                Convert the IP address to the host name using gethostbyaddr().

                rahuljin wrote:

                ...it crashes.

                Meaning what? A "crash" is fairly meaningless.

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                R 1 Reply Last reply
                0
                • D David Crow

                  rahuljin wrote:

                  will this program work on a network of computers too ?

                  That's what NetServerEnum() is for.

                  rahuljin wrote:

                  suppose i run it on a client, will it give the info of server or all the computers in the network (clients + servers) ?

                  First, did you try it? Second, did you check MSDN to see how OpenSCManager() handles its first argument?

                  rahuljin wrote:

                  also, if i have the ip address of the server then how to use it in this program ?

                  Convert the IP address to the host name using gethostbyaddr().

                  rahuljin wrote:

                  ...it crashes.

                  Meaning what? A "crash" is fairly meaningless.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  R Offline
                  R Offline
                  rahuljin
                  wrote on last edited by
                  #11

                  here is error from windows. it says "new01" has stopped working

                  Problem signature:
                  Problem Event Name: APPCRASH
                  Application Name: new01.exe
                  Application Version: 0.0.0.0
                  Application Timestamp: 4a349ab0
                  Fault Module Name: RPCRT4.dll
                  Fault Module Version: 6.1.7100.0
                  Fault Module Timestamp: 49eea681
                  Exception Code: c0000005
                  Exception Offset: 0002f3b0
                  OS Version: 6.1.7100.2.0.0.256.1
                  Locale ID: 16393
                  Additional Information 1: 0a9e
                  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
                  Additional Information 3: 0a9e
                  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

                  Read our privacy statement online:
                  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

                  If the online privacy statement is not available, please read our privacy statement offline:
                  C:\Windows\system32\en-US\erofflps.txt

                  here is the complete code of the program ----

                  // setting unicode

                  #ifndef UNICODE
                  #define UNICODE
                  #endif

                  // header files
                  #include <stdio.h>
                  #include <assert.h>
                  #include <windows.h>
                  #include <lm.h>
                  #include <tchar.h>
                  #include <wchar.h>

                  void printServer(LPSERVER_INFO_101 ppTmpBuf, DWORD ddwEntriesRead)
                  {
                  SC_HANDLE hSCM;
                  SERVICE_STATUS ss;
                  DWORD i;
                  short int j, x;
                  x = 2;
                  wchar_t* prName[] = {

                                      \_T("W3SVC"), 
                                      \_T("Themes")
                                      
                                      };
                  
                  for (i = 0; i < ddwEntriesRead; i++) 
                  {
                      for(j=0; j<x ; j++)
                      {
                          hSCM = OpenSCManager((LPCTSTR) ppTmpBuf->sv101\_name,
                              NULL, SC\_MANAGER\_CONNECT);
                          if (hSCM != NULL)
                          {
                              SC\_HANDLE hService = OpenService(hSCM, prName\[j\], SERVICE\_QUERY\_STATUS);
                              if (hService != NULL)
                              {                   
                                  if (QueryServiceStatus(hService, &ss) != FALSE)
                                  {
                                      if ((ss.dwCurrentState == SERVICE\_RUNNING)||(ss.dwCurrentState == SERVICE\_START\_PENDING))
                                          wprintf(\_T("%-20s %-15s This service is running.\\n"),ppTmpBuf->sv101\_name, prName\[j\]);
                                      else 
                                          wprintf(\_T("%-20s %-15s This service is stopped or not found.\\n"),ppTmpBuf->sv101\_name, prName\[j\]); 
                                  }
                                  CloseServiceHandle(hService);
                              }
                  
                  D 1 Reply Last reply
                  0
                  • R rahuljin

                    here is error from windows. it says "new01" has stopped working

                    Problem signature:
                    Problem Event Name: APPCRASH
                    Application Name: new01.exe
                    Application Version: 0.0.0.0
                    Application Timestamp: 4a349ab0
                    Fault Module Name: RPCRT4.dll
                    Fault Module Version: 6.1.7100.0
                    Fault Module Timestamp: 49eea681
                    Exception Code: c0000005
                    Exception Offset: 0002f3b0
                    OS Version: 6.1.7100.2.0.0.256.1
                    Locale ID: 16393
                    Additional Information 1: 0a9e
                    Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
                    Additional Information 3: 0a9e
                    Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

                    Read our privacy statement online:
                    http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

                    If the online privacy statement is not available, please read our privacy statement offline:
                    C:\Windows\system32\en-US\erofflps.txt

                    here is the complete code of the program ----

                    // setting unicode

                    #ifndef UNICODE
                    #define UNICODE
                    #endif

                    // header files
                    #include <stdio.h>
                    #include <assert.h>
                    #include <windows.h>
                    #include <lm.h>
                    #include <tchar.h>
                    #include <wchar.h>

                    void printServer(LPSERVER_INFO_101 ppTmpBuf, DWORD ddwEntriesRead)
                    {
                    SC_HANDLE hSCM;
                    SERVICE_STATUS ss;
                    DWORD i;
                    short int j, x;
                    x = 2;
                    wchar_t* prName[] = {

                                        \_T("W3SVC"), 
                                        \_T("Themes")
                                        
                                        };
                    
                    for (i = 0; i < ddwEntriesRead; i++) 
                    {
                        for(j=0; j<x ; j++)
                        {
                            hSCM = OpenSCManager((LPCTSTR) ppTmpBuf->sv101\_name,
                                NULL, SC\_MANAGER\_CONNECT);
                            if (hSCM != NULL)
                            {
                                SC\_HANDLE hService = OpenService(hSCM, prName\[j\], SERVICE\_QUERY\_STATUS);
                                if (hService != NULL)
                                {                   
                                    if (QueryServiceStatus(hService, &ss) != FALSE)
                                    {
                                        if ((ss.dwCurrentState == SERVICE\_RUNNING)||(ss.dwCurrentState == SERVICE\_START\_PENDING))
                                            wprintf(\_T("%-20s %-15s This service is running.\\n"),ppTmpBuf->sv101\_name, prName\[j\]);
                                        else 
                                            wprintf(\_T("%-20s %-15s This service is stopped or not found.\\n"),ppTmpBuf->sv101\_name, prName\[j\]); 
                                    }
                                    CloseServiceHandle(hService);
                                }
                    
                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #12

                    So where's the problem?

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    R 1 Reply Last reply
                    0
                    • D David Crow

                      So where's the problem?

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      R Offline
                      R Offline
                      rahuljin
                      wrote on last edited by
                      #13

                      when i remove the following statements from the program, program run without any error.

                      NetApiBufferFree(ppTmpBuf);
                      NetApiBufferFree(pTmpBuf);

                      what may be the problem with this ?

                      D 1 Reply Last reply
                      0
                      • R rahuljin

                        when i remove the following statements from the program, program run without any error.

                        NetApiBufferFree(ppTmpBuf);
                        NetApiBufferFree(pTmpBuf);

                        what may be the problem with this ?

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #14

                        rahuljin wrote:

                        what may be the problem with this ?

                        It appears you are freeing the same memory three times.

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        R 1 Reply Last reply
                        0
                        • D David Crow

                          rahuljin wrote:

                          what may be the problem with this ?

                          It appears you are freeing the same memory three times.

                          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          R Offline
                          R Offline
                          rahuljin
                          wrote on last edited by
                          #15

                          yes, that may be the reason for the program crash. is there a way to access from a client if it have minimum access ? i mean that the client can access only a few folder in the other pc. also when i try this program on xp OS system, it gives the error --- NetQueryDisplayInformation gave error ERROR_ACCESS_DENIED. Due to this error, it does not display the status of service even of the system it is running on. it is a client pc. though i can ping the ip of other computers in the network. is there any remedy for this ?

                          modified on Tuesday, June 16, 2009 3:50 AM

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups