#include <windows.h>
#include <lm.h>
#include <stdio.h>
#include <stdlib.h>
#pragma hdrstop



#define MAXLEN 256



int main( int argc, char *argv[] )
{
	BYTE *buf;
	DWORD read, total, resumeh, rc, i;
	wchar_t server[MAXLEN], *p;

	if ( argc != 2 )
	{
		puts( "usage: nsde \\\\server" );
		return 1;
	}

	mbstowcs( server, argv[1], MAXLEN );

	resumeh = 0;
	do
	{
		buf = NULL;
		rc = NetServerDiskEnum( (char *) server, 0, &buf,
			2048, &read, &total, &resumeh );

		if ( rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS )
			break;

		printf( "\ngot %lu entries out of %lu\n", read, total );

		// at this point, buf holds (read) Unicode strings, like this:
		// L"A:\0C:\0D:\0"
		for ( i = 0, p = (wchar_t *) buf; i < read; ++ i, p += wcslen( p ) + 1 )
		{
			// Note: the capital S in the format string will expect Unicode
			// strings, as this is a program written/compiled for ANSI.
			printf( "Entry %lu: \"%S\"\n",i, p );
		}

		if ( buf != NULL )
			NetApiBufferFree( buf );

	} while ( rc == ERROR_MORE_DATA );

	if ( rc != ERROR_SUCCESS )
		printf( "NSE() returned %lu\n", rc );

	return 0;
}

