BOOL CLoginCtrl::EstablishConnection(LPCTSTR lpszRemote, LPCTSTR lpszResource, BOOL bEstablish)
{
  TCHAR szRemoteResource[_MAX_PATH];
   DWORD rc;
   // Remote resource, \\remote\ipc$, remote\admin$, ...
   // disconnect or connect to the resource, based on bEstablish
   //
   if ( bEstablish ) 
   {
      NETRESOURCE nr;
      nr.dwType = RESOURCETYPE_ANY;
      nr.lpLocalName = NULL;
      nr.lpRemoteName = (LPTSTR)&szRemoteResource;
      nr.lpProvider = NULL;
      
      //Establish connection (using username/pwd)
      rc = WNetAddConnection2( &nr, m_lpszPassword, m_lpszUser, FALSE );
   
      switch( rc )
      {
      case ERROR_ACCESS_DENIED:
      case ERROR_INVALID_PASSWORD:
      case ERROR_LOGON_FAILURE:
      case ERROR_SESSION_CREDENTIAL_CONFLICT:
         // Prompt for password if the default(NULL) was not good
         if ( m_lpszUser != NULL && m_lpszPassword == NULL )
         {
  CString csError;            AfxMessageBox( _T("Invalid password\n\n") );
//          SetUserAndPassword( TRUE );
            AfxMessageBox( _T("Connecting to remote service ... ") );
            //Establish connection (using username/pwd) again
            rc = WNetAddConnection2( &nr, m_lpszPassword, m_lpszUser, FALSE );
         }
         break;
      }
   }
   else 
      // Disconnect
      rc = WNetCancelConnection2( szRemoteResource, 0, NULL );
   
   if ( rc == NO_ERROR ) 
      return TRUE; // indicate success   SetLastError( rc );   return FALSE;}//下面是调用上面的函数的程序
if ( !EstablishConnection( m_lpszMachine, _T("ADMIN$"), TRUE ) )
   {
      rc = -2;
  throw "连接到主机\\Admin$失败";
   }
   // Connect to remote machine IPC$
   //建立与IPC的连接
   if ( !EstablishConnection( m_lpszMachine, _T("IPC$"), TRUE ) )
   {
      rc = -2;
      throw "连接到主机\\IPC$失败";
   }我用上面的代码都可以成功连接Windows2000,NT,2003 Server操作系统等,但现在发现这段代码无法实现对XP系统进行远程连接,是不是XP系统做了某种安全设置需要开启?还望高手指点一下!谢谢!