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