Article ID: 152823
Article Last Modified on 3/21/2005
/* Compile options needed:
Be sure to include the mpr.lib library when linking.
*/
#include <windows.h>
#include <winnetwk.h>
#include <stdio.h>
void main ( void )
{
NETRESOURCE resourcebuffer[5000];
HANDLE hEnum;
DWORD netRet, dwEntriesToGet=0XFFFFFFFF;
DWORD dwSizeResourcebuffer = sizeof( resourcebuffer);
//
// Enumerate starting at the root of the network
//
netRet = WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_DISK,
(RESOURCEUSAGE_CONNECTABLE |
RESOUCEUSAGE_CONTAINER),
(LPNETRESOURCE)NULL,
&hEnum);
if( netRet == NO_ERROR )
{
//
// The WNetOpenEnum was successful. Now get all the network
providers
for
// the network.
//
netRet = WNetEnumResource( hEnum,
(LPDWORD)&dwEntriesToGet,
(LPVOID)resourcebuffer,
(LPDWORD)&dwSizeResourcebuffer);
if( netRet == NO_ERROR )
{
//
// The resourcebuffer contains the network providers. Take a
look at
// the lpRemoteName field. ON win 95, this field will be NULL,
on NT
// the field will match the lpProvider field
//
DWORD i;
for( i = 0; i < dwEntriesToGet; i++ )
{
if( resourcebuffer[i].lpRemoteName ) printf("Remote Name:
%s\n",
resourcebuffer[i].lpRemoteName);
else printf("Remote Name: IS NULL\n");
printf( "Network Provider: %s\n\n",
resourcebuffer[i].lpProvider );
}
}
else printf("ERROR: WNetEnumResource API failed : %ld\n", netRet );
}
else printf("ERROR: WNetOpenEnum API Failed: %ld\n", netRet);
}
Keywords: kbapi kbnetwork kbprb KB152823