1 #include <windows.h> 2 #include <stdio.h> 3 4 DWORD debug_shift = 0; 5 6 #define INC_SHIFT ++debug_shift; 7 #define DEC_SHIFT --debug_shift; 8 #define PRT_SHIFT do { DWORD cur = 0; for (; cur < debug_shift; ++cur) printf("\t"); } while (0); 9 10 void np_enum(NETRESOURCEW * resource) 11 { 12 DWORD ret; 13 HANDLE handle; 14 DWORD size = 0x1000; 15 NETRESOURCEW * out; 16 BOOL check = FALSE; 17 18 if (resource && resource->lpRemoteName) 19 check = TRUE; 20 21 ret = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, resource, &handle); 22 if (ret != WN_SUCCESS) 23 return; 24 25 out = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); 26 if (!out) 27 { 28 WNetCloseEnum(handle); 29 return; 30 } 31 32 INC_SHIFT 33 34 if (check) 35 { 36 printf("Called with lpRemoteName not null, current value: %S\n", resource->lpRemoteName); 37 } 38 39 do 40 { 41 DWORD count = -1; 42 43 ret = WNetEnumResource(handle, &count, out, &size); 44 if (ret == WN_SUCCESS || ret == WN_MORE_DATA) 45 { 46 NETRESOURCEW * current; 47 48 current = out; 49 for (; count; count--) 50 { 51 PRT_SHIFT; 52 printf("lpRemoteName: %S\n", current->lpRemoteName); 53 54 if ((current->dwUsage & RESOURCEUSAGE_CONTAINER) == RESOURCEUSAGE_CONTAINER) 55 { 56 PRT_SHIFT; 57 printf("Found provider: %S\n", current->lpProvider); 58 np_enum(current); 59 } 60 61 current++; 62 } 63 } 64 } while (ret != WN_NO_MORE_ENTRIES); 65 DEC_SHIFT; 66 67 HeapFree(GetProcessHeap(), 0, out); 68 WNetCloseEnum(handle); 69 } 70 71 int wmain(int argc, const WCHAR *argv[]) 72 { 73 np_enum(NULL); 74 75 return 0; 76 } 77