hi

什么网络监视器?查看谁链接到你的机器吗?MSDN里有例子。

解决方案 »

  1.   

    Windows NT/2000/XP#ifndef UNICODE
    #define UNICODE
    #endif#include <stdio.h>
    #include <assert.h>
    #include <windows.h> 
    #include <lm.h>int wmain(int argc, wchar_t *argv[])
    {
       LPSESSION_INFO_10 pBuf = NULL;
       LPSESSION_INFO_10 pTmpBuf;
       DWORD dwLevel = 10;
       DWORD dwPrefMaxLen = -1;
       DWORD dwEntriesRead = 0;
       DWORD dwTotalEntries = 0;
       DWORD dwResumeHandle = 0;
       DWORD i;
       DWORD dwTotalCount = 0;
       LPTSTR pszServerName = NULL;
       LPTSTR pszClientName = NULL;
       LPTSTR pszUserName = NULL;
       NET_API_STATUS nStatus;
       //
       // Check command line arguments.
       //
       if (argc > 4)
       {
          wprintf(L"Usage: %s [\\\\ServerName] [\\\\ClientName] [UserName]\n", argv[0]);
          exit(1);
       }   if (argc >= 2)
          pszServerName = argv[1];   if (argc >= 3)
          pszClientName = argv[2];   if (argc == 4)
          pszUserName = argv[3];
       //
       // Call the NetSessionEnum function, specifying level 10.
       //
       do // begin do
       {
          nStatus = NetSessionEnum(pszServerName,
                                   pszClientName,
                                   pszUserName,
                                   dwLevel,
                                   (LPBYTE*)&pBuf,
                                   dwPrefMaxLen,
                                   &dwEntriesRead,
                                   &dwTotalEntries,
                                   &dwResumeHandle);
          //
          // If the call succeeds,
          //
          if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
          {
             if ((pTmpBuf = pBuf) != NULL)
             {
                //
                // Loop through the entries.
                //
                for (i = 0; (i < dwEntriesRead); i++)
                {
                   assert(pTmpBuf != NULL);               if (pTmpBuf == NULL)
                   {
                      fprintf(stderr, "An access violation has occurred\n");
                      break;
                   }
                   //
                   // Print the retrieved data. 
                   //
                   wprintf(L"\n\tClient: %s\n", pTmpBuf->sesi10_cname);
                   wprintf(L"\tUser:   %s\n", pTmpBuf->sesi10_username);
                   printf("\tActive: %d\n", pTmpBuf->sesi10_time);
                   printf("\tIdle:   %d\n", pTmpBuf->sesi10_idle_time);               pTmpBuf++;
                   dwTotalCount++;
                }
             }
          }
          //
          // Otherwise, indicate a system error.
          //
          else
             fprintf(stderr, "A system error has occurred: %d\n", nStatus);
          //
          // Free the allocated memory.
          //
          if (pBuf != NULL)
          {
             NetApiBufferFree(pBuf);
             pBuf = NULL;
          }
       }
       // 
       // Continue to call NetSessionEnum while 
       //  there are more entries. 
       // 
       while (nStatus == ERROR_MORE_DATA); // end do   // Check again for an allocated buffer.
       //
       if (pBuf != NULL)
          NetApiBufferFree(pBuf);
       //
       // Print the final count of sessions enumerated.
       //
       fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);   return 0;
    }
      

  2.   

    Windows 95/98/Me#include <stdio.h>
    #include <assert.h>
    #include <windows.h> 
    #include <svrapi.h>const short MAX_ENTRIES = 20;int main(int argc, char FAR * argv[])
    {
       char FAR * pszServerName = NULL;
       short nLevel = 50;
       struct session_info_50* pBuf = NULL;
       struct session_info_50* pTmpBuf = NULL;
       short cbBuffer;
       short nEntriesRead = 0;
       short nTotalEntries = 0;
       short nTotalCount = 0;
       int i;
       NET_API_STATUS nStatus;
       //
       // ServerName can be NULL to indicate the local computer.
       //
       if (argc > 2)
       {
          printf("Usage: %s [\\\\ServerName]\n", argv[0]);
          exit(1);
       }   if (argc == 2)
          pszServerName = argv[1];   cbBuffer = MAX_ENTRIES * sizeof(struct session_info_50);
       //
       // Allocate the memory required to receive a maximum of
       //  20 session_info_50 structures.
       //
       pBuf = malloc(cbBuffer);   if (pBuf == NULL)
          printf("No memory\n");   // Call the NetSessionEnum function to list the
       //  sessions, specifying information level 50.
       //
       nStatus = NetSessionEnum(pszServerName,
                                nLevel,
                                (char FAR *)pBuf,
                                cbBuffer,
                                &nEntriesRead,
                                &nTotalEntries);
       //
       // Loop through the entries; process errors.
       //
       if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
       {
          if ((pTmpBuf = pBuf) != NULL)
          {
             for (i = 0; (i < nEntriesRead); i++)
             {
                assert(pTmpBuf != NULL);            if (pTmpBuf == NULL)
                {
                   fprintf(stderr, "An access violation has occurred\n");
                   break;
                }
                //
                // Display the information for each entry retrieved.
                //
                printf("\n\tClient: %s\n", pTmpBuf->sesi50_cname);
                printf("\tUser:   %s\n", pTmpBuf->sesi50_username);
                printf("\tActive: %d\n", pTmpBuf->sesi50_time);
                printf("\tIdle:   %d\n", pTmpBuf->sesi50_idle_time);
                printf("\tKey:   %d\n", pTmpBuf->sesi50_key);            pTmpBuf++;
                nTotalCount++;
             }
          }
       }
       else
          fprintf(stderr, "A system error has occurred: %d\n", nStatus);
       //
       // Display a warning if the buffer was not large enough
       //  to contain all available entries.
       //
       if ((nEntriesRead < nTotalEntries) || (nStatus == ERROR_MORE_DATA))
          fprintf(stderr, "Not all entries have been enumerated\n");
       //
       // Free the allocated memory.
       //
       if (pBuf != NULL)
          free(pBuf);   fprintf(stderr, "\nTotal of %d entries enumerated\n", nTotalCount);   return 0;
    }
      

  3.   

    是这个啊。去我主页看看。
    http://nowcan.yeah.net