在msdn中,NetShareEnum是这样描述的:NetShareEnum retrieves information about each shared resource on a server. The NetShareEnum function is obsolete. It is provided only for compatibility with LAN Manager and 16-bit versions of Windows. Win32-based applications should use the WNetEnumResource function.即获得在服务器上的每个共享资源,在16位机器上使用,已经过时了,win32位应用程序应该使用WNetEnumResource 函数。
而WNetEnumResource的描述是:The WNetEnumResource function continues a network-resource enumeration started by the WNetOpenEnum function.
即枚举网络资源。
问题:1、网络资源包括局域网共享目录下的文件吗?
2、WNetEnumResource 能否代替NetShareEnum 列出局域网中所有共享目录下的文件?
3、在使用中,它们如何配合?
而WNetEnumResource的描述是:The WNetEnumResource function continues a network-resource enumeration started by the WNetOpenEnum function.
即枚举网络资源。
问题:1、网络资源包括局域网共享目录下的文件吗?
2、WNetEnumResource 能否代替NetShareEnum 列出局域网中所有共享目录下的文件?
3、在使用中,它们如何配合?
解决方案 »
- 服务器有几十G的内存你一般怎么用?
- 动态按钮的响应问题ON_CONTROL_RANGE
- 请问如何使用dll文件里的资源ID
- SOCKET 通信
- SMTP客户端AUTH认证简单问题~~~~~~~~~~
- 呵呵,发布一个软件:Cybersearch V1.0(网络搜索器)~~~~~~~~~
- 怎样生成Automation类型的DLL?
- 为什么用WINSOCK写的程序可以接受UNIX发送的数据,返回给UNIX的数据UNIX却收不到?
- 请问一个关于非模态对话框和视图的问题
- 左(TreeView)右(ListView)视图的问题
- fat32 分区格式化,盘的容量大小在fat32的哪个扇区的哪个位置?
- 怎么用正则表达式匹配含有二进制数据的url
2、当然
3、配合什么?WNetEnumResource和NetShareEnum??
BOOL WINAPI EnumerateFunc(HWND hwnd,
HDC hdc,
LPNETRESOURCE lpnr)
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = -1; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;
//
// Call the WNetOpenEnum function to begin the enumeration.
//
dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources
RESOURCETYPE_ANY, // all resources
0, // enumerate all resources
lpnr, // NULL first time the function is called
&hEnum); // handle to the resource
if (dwResult != NO_ERROR)
{
//
// Process errors with an application-defined error handler.
//
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
return FALSE;
}
//
// Call the GlobalAlloc function to allocate resources.
//
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
do
{
//
// Initialize the buffer.
//
ZeroMemory(lpnrLocal, cbBuffer);
//
// Call the WNetEnumResource function to continue
// the enumeration.
//
dwResultEnum = WNetEnumResource(hEnum, // resource handle
&cEntries, // defined locally as -1
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size
//
// If the call succeeds, loop through the structures.
//
if (dwResultEnum == NO_ERROR)
{
for(i = 0; i < cEntries; i++)
{
// Call an application-defined function to
// display the contents of the NETRESOURCE structures.
//
DisplayStruct(hdc, &lpnrLocal[i]);
// If the NETRESOURCE structure represents a container resource,
// call the EnumerateFunc function recursively.
if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage
& RESOURCEUSAGE_CONTAINER))
if(!EnumerateFunc(hwnd, hdc, &lpnrLocal[i]))
TextOut(hdc, 10, 10, "EnumerateFunc returned FALSE.", 29);
}
}
// Process errors.
//
else if (dwResultEnum != ERROR_NO_MORE_ITEMS)
{
NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
break;
}
}
//
// End do.
//
while(dwResultEnum != ERROR_NO_MORE_ITEMS);
//
// Call the GlobalFree function to free the memory.
//
GlobalFree((HGLOBAL)lpnrLocal);
//
// Call WNetCloseEnum to end the enumeration.
//
dwResult = WNetCloseEnum(hEnum);
if(dwResult != NO_ERROR)
{
//
// Process errors.
//
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
return FALSE;
}
return TRUE;
} 这段代码将会通过递归调用实现遍历文件并显示到一个DC中,MSDN的例子
DisplayStruct是用户自定义打印信息的,可以是printf();
NetErrorHandler 用户自定义打印错误信息的。不用管 屏蔽掉。
调用时 EnumerateFunc(NULL,NULL,NULL);