1个回答
展开全部
1. 使用
int DimCount;
void main()
{
LPNETRESOURCE lpNetRC_p=NULL;
DimCount=0;
Enumerate(lpNetRC_p) ;
}
2.回调函数
bool Enumerate(LPNETRESOURCE lpNetRC_p)
{
int UserCount=0;
HANDLE hEnum = 0;
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY;
DWORD dwResult = WNetOpenEnum(
dwScope, // scope of enumeration
dwType, // resource types to list
0, // enumerate all resources or RESOURCEUSAGE_CONTAINER
lpNetRC_p, // pointer to resource structure (NULL at first time)
&hEnum // handle to resource
);
if( dwResult != NO_ERROR )
{
int re=GetLastError();
return FALSE;
}
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpBuffer;
// first allocate buffer for NETRESOURCE structures ...
lpBuffer=(LPNETRESOURCE)GlobalAlloc(GPTR,dwBuffer ) ;
dwResult = WNetEnumResource(hEnum,&dwEntries,lpBuffer,&dwBuffer);
if( dwResult == NO_ERROR )
{
for( register DWORD i = 0 ; i <dwEntries;i++)
{
// memcpy(&lpBuffer[i],&lpBuffer[i],sizeof(NETRESOURCE));
if(lpNetRC_p)
{
if(lpBuffer[i].dwDisplayType==RESOURCEDISPLAYTYPE_DOMAIN)
{
//这里就是得到获取本机 域名 或 工作组名并把它放到数组中
strcpy((char *)DimInfo[DimCount++].dimName,lpBuffer[i].lpRemoteName);
}
else
{ //这里就是得到的用户名并把它放到数组中
strcpy((char *)DimInfo[DimCount-1].User[UserCount++].UserName,lpBuffer[i].lpRemoteName+2);
if(UserCount>=20)UserCount=0;
}
}
DWORD a=lpBuffer[i].dwDisplayType,c=lpBuffer[i].dwUsage;
//RESOURCEUSAGE_CONTAINER == (lpBuffer[i].dwUsage & RESOURCEUSAGE_CONTAINER)
//上面的条件枚举所有的网络资源
if(a==6||a&RESOURCEDISPLAYTYPE_DOMAIN==RESOURCEDISPLAYTYPE_DOMAIN||c&RESOURCEUSAGE_CONTAINER==RESOURCEUSAGE_CONTAINER)
{
if(!Enumerate(&lpBuffer[i]))
{
return FALSE;
}
//strcpy((char *)User[UserCount++].UserName,lpBuffer[i].lpRemoteName+2);
//if(UserCount>=20)UserCount=0;
}
}
}
else if(dwResult != ERROR_NO_MORE_ITEMS)
{
return FALSE;
}
if(lpBuffer) GlobalFree((HGLOBAL) lpBuffer) ;
WNetCloseEnum(hEnum) ;
return TRUE;
}
int DimCount;
void main()
{
LPNETRESOURCE lpNetRC_p=NULL;
DimCount=0;
Enumerate(lpNetRC_p) ;
}
2.回调函数
bool Enumerate(LPNETRESOURCE lpNetRC_p)
{
int UserCount=0;
HANDLE hEnum = 0;
DWORD dwScope = RESOURCE_GLOBALNET ;
DWORD dwType = RESOURCETYPE_ANY;
DWORD dwResult = WNetOpenEnum(
dwScope, // scope of enumeration
dwType, // resource types to list
0, // enumerate all resources or RESOURCEUSAGE_CONTAINER
lpNetRC_p, // pointer to resource structure (NULL at first time)
&hEnum // handle to resource
);
if( dwResult != NO_ERROR )
{
int re=GetLastError();
return FALSE;
}
DWORD dwBuffer = 16384 ; // 16K is reasonable size
DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
LPNETRESOURCE lpBuffer;
// first allocate buffer for NETRESOURCE structures ...
lpBuffer=(LPNETRESOURCE)GlobalAlloc(GPTR,dwBuffer ) ;
dwResult = WNetEnumResource(hEnum,&dwEntries,lpBuffer,&dwBuffer);
if( dwResult == NO_ERROR )
{
for( register DWORD i = 0 ; i <dwEntries;i++)
{
// memcpy(&lpBuffer[i],&lpBuffer[i],sizeof(NETRESOURCE));
if(lpNetRC_p)
{
if(lpBuffer[i].dwDisplayType==RESOURCEDISPLAYTYPE_DOMAIN)
{
//这里就是得到获取本机 域名 或 工作组名并把它放到数组中
strcpy((char *)DimInfo[DimCount++].dimName,lpBuffer[i].lpRemoteName);
}
else
{ //这里就是得到的用户名并把它放到数组中
strcpy((char *)DimInfo[DimCount-1].User[UserCount++].UserName,lpBuffer[i].lpRemoteName+2);
if(UserCount>=20)UserCount=0;
}
}
DWORD a=lpBuffer[i].dwDisplayType,c=lpBuffer[i].dwUsage;
//RESOURCEUSAGE_CONTAINER == (lpBuffer[i].dwUsage & RESOURCEUSAGE_CONTAINER)
//上面的条件枚举所有的网络资源
if(a==6||a&RESOURCEDISPLAYTYPE_DOMAIN==RESOURCEDISPLAYTYPE_DOMAIN||c&RESOURCEUSAGE_CONTAINER==RESOURCEUSAGE_CONTAINER)
{
if(!Enumerate(&lpBuffer[i]))
{
return FALSE;
}
//strcpy((char *)User[UserCount++].UserName,lpBuffer[i].lpRemoteName+2);
//if(UserCount>=20)UserCount=0;
}
}
}
else if(dwResult != ERROR_NO_MORE_ITEMS)
{
return FALSE;
}
if(lpBuffer) GlobalFree((HGLOBAL) lpBuffer) ;
WNetCloseEnum(hEnum) ;
return TRUE;
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |