Click here to Skip to main content
15,887,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: [help]detect the status of iis server Pin
David Crow9-Jun-09 9:23
David Crow9-Jun-09 9:23 
GeneralRe: [help]detect the status of iis server Pin
rahuljin9-Jun-09 10:38
rahuljin9-Jun-09 10:38 
GeneralRe: [help]detect the status of iis server Pin
David Crow10-Jun-09 3:43
David Crow10-Jun-09 3:43 
GeneralRe: [help]detect the status of iis server Pin
rahuljin12-Jun-09 1:46
rahuljin12-Jun-09 1:46 
GeneralRe: [help]detect the status of iis server Pin
David Crow12-Jun-09 3:06
David Crow12-Jun-09 3:06 
GeneralRe: [help]detect the status of iis server [modified] Pin
rahuljin12-Jun-09 4:35
rahuljin12-Jun-09 4:35 
QuestionRe: [help]detect the status of iis server Pin
David Crow13-Jun-09 12:41
David Crow13-Jun-09 12:41 
AnswerRe: [help]detect the status of iis server [modified] Pin
rahuljin13-Jun-09 20:42
rahuljin13-Jun-09 20:42 
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);
                }              
            }
             CloseServiceHandle(hSCM);
        }
        ppTmpBuf++;
    }
    NetApiBufferFree(ppTmpBuf);
}





void debugeFunct(NET_API_STATUS nState, LPSERVER_INFO_101 pTmpBuf, 
                 DWORD dwEntriesRead, DWORD dwTotalEntries)
{
    NET_API_STATUS nas ;
    NET_DISPLAY_MACHINE * pndm;
    DWORD dwNdmCount;
    
    switch(nState)
    {
    case NERR_Success:
    case ERROR_MORE_DATA:
        {
            if(pTmpBuf == NULL)
            {
                fprintf(stderr, "An access voilation has occurred.\n");
            }

            else
            {
                nas = NetQueryDisplayInformation (pTmpBuf->sv101_name,
                                                       2,
                                                       0,
                                                       1,
                                                       sizeof(NET_DISPLAY_MACHINE),
                                                       &dwNdmCount,
                                                       (PVOID*)&pndm);
                switch (nas)
                {                    
                case NERR_Success:
                case ERROR_MORE_DATA:
                    printServer(pTmpBuf, dwEntriesRead);
                    break;
                
                default:
                    {
                       printf("NQDI gave error %u\n", nas);
                       break;
                     }
                }
            }
        }
        break;

    default:
        printf("No pc were found. The buffer returned was NULL\n");
        break;


    }
    NetApiBufferFree(pTmpBuf);
}


void findServ(DWORD dwPrefMaxLen, DWORD dwServerType)
{
    LPSERVER_INFO_101 pBuf = NULL;
    DWORD dwLevel = 101;
    DWORD dwEntriesRead = 0;
    DWORD dwTotalEntries = 0;
    DWORD dwTotalCount = 0;
    DWORD dwResumeHandle = 0;
    NET_API_STATUS nStatus;
    LPTSTR pszServerName = NULL;
    LPTSTR pszDomainName = NULL;
 

 
    nStatus = NetServerEnum(
                            (LPCWSTR) pszServerName,
                            dwLevel,
                            (LPBYTE *) & pBuf,
                            dwPrefMaxLen,
                            &dwEntriesRead,
                            &dwTotalEntries,
                            dwServerType, 
                            (LPCWSTR) pszDomainName, 
                            &dwResumeHandle
                            );
    
    
    debugeFunct(nStatus, pBuf, dwEntriesRead, dwTotalEntries);
    NetApiBufferFree(pBuf);

}

     
  
int _tmain(int argc, wchar_t * argv[])
{
    DWORD dPrefMaxLen = MAX_PREFERRED_LENGTH;
    DWORD dServerType = SV_TYPE_SERVER;
    printf("Machine              Service         Status\n");
    while(1)
    {
    findServ(dPrefMaxLen, dServerType);
    Sleep(3000);
    }
    return 0;
}
Here is the event viewer file of the application

modified on Sunday, June 14, 2009 10:33 AM

QuestionRe: [help]detect the status of iis server Pin
David Crow14-Jun-09 10:03
David Crow14-Jun-09 10:03 
AnswerRe: [help]detect the status of iis server Pin
rahuljin14-Jun-09 11:19
rahuljin14-Jun-09 11:19 
AnswerRe: [help]detect the status of iis server Pin
David Crow15-Jun-09 3:57
David Crow15-Jun-09 3:57 
GeneralRe: [help]detect the status of iis server [modified] Pin
rahuljin15-Jun-09 5:26
rahuljin15-Jun-09 5:26 
QuestionHi! VC console GUI Pin
tuan11118-Jun-09 17:42
tuan11118-Jun-09 17:42 
AnswerRe: Hi! VC console GUI Pin
Chandrasekharan P8-Jun-09 18:08
Chandrasekharan P8-Jun-09 18:08 
AnswerRe: Hi! VC console GUI Pin
Cedric Moonen8-Jun-09 20:19
Cedric Moonen8-Jun-09 20:19 
AnswerRe: Hi! VC console GUI Pin
Michael Schubert9-Jun-09 0:44
Michael Schubert9-Jun-09 0:44 
QuestionHow to convert a VARIANT buffer to a byte buffer? Pin
gpenghe8-Jun-09 17:00
gpenghe8-Jun-09 17:00 
AnswerRe: How to convert a VARIANT buffer to a byte buffer? Pin
«_Superman_»8-Jun-09 19:23
professional«_Superman_»8-Jun-09 19:23 
GeneralRe: How to convert a VARIANT buffer to a byte buffer? Pin
gpenghe8-Jun-09 23:38
gpenghe8-Jun-09 23:38 
GeneralRe: How to convert a VARIANT buffer to a byte buffer? Pin
«_Superman_»9-Jun-09 5:33
professional«_Superman_»9-Jun-09 5:33 
GeneralRe: How to convert a VARIANT buffer to a byte buffer? Pin
gpenghe9-Jun-09 5:43
gpenghe9-Jun-09 5:43 
QuestionHow to display '&' text on CMFCToolBarButton Pin
Un Suthee8-Jun-09 10:41
Un Suthee8-Jun-09 10:41 
AnswerRe: How to display '&' text on CMFCToolBarButton Pin
Rajesh R Subramanian8-Jun-09 11:11
professionalRajesh R Subramanian8-Jun-09 11:11 
GeneralRe: How to display '&' text on CMFCToolBarButton Pin
Un Suthee8-Jun-09 12:47
Un Suthee8-Jun-09 12:47 
GeneralRe: How to display '&' text on CMFCToolBarButton Pin
«_Superman_»8-Jun-09 15:39
professional«_Superman_»8-Jun-09 15:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.