This is a sample program to demonstrate how to enumerate resources on the
network, using the WNetOpenEnum() Win32 API function. The program is short, and almost self explanatory, but there are a couple of things worth mentioning.
WNetResourceEnum(), you should allocate a buffer to receive the data, 16K is a typical value used, and then call
WNetResourceEnum() as many times are needed to get all the info. Also notice, that the function only gets resources one level deep. To go deeper, you have to recursively call
WNetOpenEnum() for each container, passing to it the NETRESOURCE structure you get from
One more thing: because the sample is written in a recursive way, it could cause a stack overflow when run on a large network. Without anything further, here’s the code:
Update: May 12 – 2000: Thanks to Stefan Kuhr for pointing out to me a little bug that would cause a buffer overrun on large networks. It’s now corrected. Thanks Stephan!