WNetCancelConnection2
NetSessionDel

解决方案 »

  1.   

    TO masterz():我基本上就把MSDN的例子复制下来,但是如下调用NetSessionDel()不成功,错误说ClientNameNotFound。可是,如果把NetSessionDel()的第二个参改成NULL,就可以成功了。请你再帮帮我,指点指点,谢谢! 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;   do // begin do
       {
          nStatus = NetSessionEnum(NULL/*pszServerName*/,
                                   NULL/*pszClientName*/,
                                   NULL/*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);
                   TRACE("\tActive: %d\n", pTmpBuf->sesi10_time);
                   TRACE("\tIdle:   %d\n", pTmpBuf->sesi10_idle_time);    DWORD d=::NetSessionDel(NULL,pTmpBuf->sesi10_cname,pTmpBuf->sesi10_username);
       if(d!=NERR_Success)
       {
       ::AfxMessageBox("Error");
       }
                   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);
      

  2.   

    我想断开与本机相连的所有计算机为什么用NetSessionDel(NULL,NULL,NULL)返回87(参数不正确)的错误代码?