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. Shared network resources

Shared network resources

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelp
3 Posts 2 Posters 0 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.
  • D Offline
    D Offline
    Daniel Visan
    wrote on last edited by
    #1

    Suppose i know the name of a computer of my network...how do i find shared resources belonging that computer (like those which appears in Network neighborhood)? I also mention that FindFirstFile("\\\\comp_name\\directory_name\\*.*",...) WORKS.IN COMMAND PROMPT DIR \\comp_name\\directory_name WORKS TOO. But FindFirstFile("\\\\comp_name\\*.*",....) fails. IN COMMAND PROMPT dir \\comp_name FAILS TOO. IN EXCHANGE, NET VIEW \\comp_name RETURN EXACTLY WHAT I NEED. My conclusion is FindFirstFile doesn't solve my problem. I tried WNet but i failed... Thank you all.

    A 1 Reply Last reply
    0
    • D Daniel Visan

      Suppose i know the name of a computer of my network...how do i find shared resources belonging that computer (like those which appears in Network neighborhood)? I also mention that FindFirstFile("\\\\comp_name\\directory_name\\*.*",...) WORKS.IN COMMAND PROMPT DIR \\comp_name\\directory_name WORKS TOO. But FindFirstFile("\\\\comp_name\\*.*",....) fails. IN COMMAND PROMPT dir \\comp_name FAILS TOO. IN EXCHANGE, NET VIEW \\comp_name RETURN EXACTLY WHAT I NEED. My conclusion is FindFirstFile doesn't solve my problem. I tried WNet but i failed... Thank you all.

      A Offline
      A Offline
      Andres Manggini
      wrote on last edited by
      #2

      Hi, you can do it using this functions: WNetOpenEnum WNetEnumResource You'll find all the information on MSDN. I wrote a little program that walks through all machines in the local network looking for shared directories (it was 3 or 4 years ago), this is a snippet: void CNetScanDlg::StartScan() { ULONG ulDataSize = 16000; NETRESOURCE* pData = new NETRESOURCE[ulDataSize]; DWORD dwEntries = 0xFFFFFFFF; OpenContainer(NULL); delete [] pData; } BOOL CNetScanDlg::OpenContainer(NETRESOURCE* pNetRes) { //Datos necesarios para la API de NetWorking ULONG ulDataSize = 16000; NETRESOURCE* pData = new NETRESOURCE[ulDataSize]; DWORD dwEntries = 0xFFFFFFFF; DWORD dwResult; HANDLE handle; // dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, pNetRes, &handle); if( dwResult == NO_ERROR ) { dwResult = WNetEnumResource( handle, &dwEntries, pData, &ulDataSize); if( dwResult == NO_ERROR ) { for( DWORD i = 0; i < dwEntries; i++) { AddItem( pData[i] ); if(RESOURCEUSAGE_CONTAINER == (pData[i].dwUsage & RESOURCEUSAGE_CONTAINER)) { OpenContainer( &pData[i] ); //Recursividad } } } } delete [] pData; return FALSE; } Andres Manggini. Buenos Aires - Argentina.

      A 1 Reply Last reply
      0
      • A Andres Manggini

        Hi, you can do it using this functions: WNetOpenEnum WNetEnumResource You'll find all the information on MSDN. I wrote a little program that walks through all machines in the local network looking for shared directories (it was 3 or 4 years ago), this is a snippet: void CNetScanDlg::StartScan() { ULONG ulDataSize = 16000; NETRESOURCE* pData = new NETRESOURCE[ulDataSize]; DWORD dwEntries = 0xFFFFFFFF; OpenContainer(NULL); delete [] pData; } BOOL CNetScanDlg::OpenContainer(NETRESOURCE* pNetRes) { //Datos necesarios para la API de NetWorking ULONG ulDataSize = 16000; NETRESOURCE* pData = new NETRESOURCE[ulDataSize]; DWORD dwEntries = 0xFFFFFFFF; DWORD dwResult; HANDLE handle; // dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, pNetRes, &handle); if( dwResult == NO_ERROR ) { dwResult = WNetEnumResource( handle, &dwEntries, pData, &ulDataSize); if( dwResult == NO_ERROR ) { for( DWORD i = 0; i < dwEntries; i++) { AddItem( pData[i] ); if(RESOURCEUSAGE_CONTAINER == (pData[i].dwUsage & RESOURCEUSAGE_CONTAINER)) { OpenContainer( &pData[i] ); //Recursividad } } } } delete [] pData; return FALSE; } Andres Manggini. Buenos Aires - Argentina.

        A Offline
        A Offline
        Andres Manggini
        wrote on last edited by
        #3

        this one could be helpful too: BOOL CNetScanDlg::AddItem(NETRESOURCE NetRes) { // CSADDR_INFO AddrInfo[100]; // DWORD dwSize = sizeof(CSADDR_INFO)*100; // HOSTENT hostent; CString strTemp; switch( NetRes.dwDisplayType ) { case RESOURCEDISPLAYTYPE_ROOT: case RESOURCEDISPLAYTYPE_NETWORK: { m_htiNetwork = m_NetTree.InsertItem( NetRes.lpRemoteName, 1, 1, TVI_ROOT ); } break; case RESOURCEDISPLAYTYPE_DOMAIN: { m_htiDomain = m_NetTree.InsertItem( NetRes.lpRemoteName, 0, 0, m_htiNetwork ); } break; case RESOURCEDISPLAYTYPE_SERVER: { m_htiServer = m_NetTree.InsertItem( NetRes.lpRemoteName, 3, 3, m_htiDomain ); //int iGetResult = /* hostent = gethostbyname(NetRes.lpRemoteName); if( iGetResult == ERROR_INSUFFICIENT_BUFFER ) m_NetTree.InsertItem("Error!", 4, 4, m_htiServer); */ //Incremento el numero de maquinas y actualizo la pantalla m_nMachines++; strTemp.Format("%d", m_nMachines); SetDlgItemText(IDC_STATIC_MAQUINAS, strTemp); // } break; case RESOURCEDISPLAYTYPE_GENERIC: case RESOURCEDISPLAYTYPE_SHARE: { //Intento listar los archivos CFileFind FileFind; CString strPath(NetRes.lpRemoteName); strPath += "\\*.*"; BOOL bResult = FileFind.FindFile(strPath, 0); // if( bResult ) //Si pude acceder a los archivos { m_NetTree.InsertItem( NetRes.lpRemoteName, 4, 4, m_htiServer ); //Incremento el nro de dir. habilitados y actualizo la pantalla m_nDirHabilitados++; strTemp.Format("%d", m_nDirHabilitados); SetDlgItemText( IDC_STATIC_DIR_HABILITADOS, strTemp ); } else //No pude acceder a ese SharePoint { m_NetTree.InsertItem( NetRes.lpRemoteName, 2, 2, m_htiServer ); //Incremento el nro de dir. Deshabilitados y actualizo la pantalla m_nDirDeshabilitados++; strTemp.Format("%d", m_nDirDeshabilitados); SetDlgItemText( IDC_STATIC_DIR_DESHABILITADOS, strTemp ); // } //Incremento el numero de directorios y actualizo la pantalla m_nDirectorios++; strTemp.Format("%d", m_nDirectorios); SetDlgItemText(IDC_STATIC_DIRECTORIOS, strTemp); // } break; default: return FALSE; } m_NetTree.Invalidate(); return TRUE; } Anybody knows how to paste a code snippet into the forum with the original formatting (like tabs) ? Andres Manggini. Buenos Aires - Argentina.

        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