首页
社区
课程
招聘
[旧帖] 如何获取1台PC所有共享资源 0.00雪花
发表于: 2013-2-28 00:41 2795

[旧帖] 如何获取1台PC所有共享资源 0.00雪花

2013-2-28 00:41
2795
网上搜索到的方法都是获取1台PC1个共享资源里所有文件与目录。我现在的需求是获取1台PC所有的共享资源,然后遍历每一个共享资源里所有文件与目录。遍历的功能我已经实现,但是如何获取所有共享资源?NetShareEnum返回值是5。我的代码如下:
        SHARE_INFO_502 shareBuffer;
        PSHARE_INFO_502 pShareTmp=NULL;
        NET_API_STATUS netApiStat=ERROR_SUCCESS;
        DWORD dwEr=0,dwTr=0,dwResume=0,i=0,dwEnumOpenStat=0,dwEnumEnumStat=0;
        in_addr ipDest;
        char* pcHost=(char*)calloc(64,sizeof(char));
        LPWSTR szWideIp=(LPWSTR)calloc(32,sizeof(WCHAR));
        BOOL bFind=FALSE;
        m_Ipv4Ctrl.GetAddress(ipDest.S_un.S_addr);
        sprintf(pcHost,"%d.%d.%d.%d",ipDest.S_un.S_un_b.s_b4,ipDest.S_un.S_un_b.s_b3,ipDest.S_un.S_un_b.s_b2,ipDest.S_un.S_un_b.s_b1);
        //GetHostNameByIp(pcHost);
        //i=MultiByteToWideChar(CP_ACP,0,pcIp,-1,NULL,0);
        MultiByteToWideChar(CP_ACP,0,pcHost,-1,szWideIp,64);
        memcpy(pcHost,szWideIp,64);
        do
        {
            netApiStat=NetShareEnum(pcHost,502,(LPBYTE*)&shareBuffer,-1,&dwEr,&dwTr,&dwResume);
            if (netApiStat==ERROR_SUCCESS||netApiStat==ERROR_MORE_DATA)
            {
                pShareTmp=&shareBuffer;
                for (i=0;i<=dwEr;i++)
                {
                    if (IsValidSecurityDescriptor(pShareTmp->shi502_security_descriptor))
                    {
                    }
                    pShareTmp++;
                }
                bFind=TRUE;
                NetApiBufferFree(pShareTmp);
            }
        } while (netApiStat==ERROR_MORE_DATA);
        
        if (bFind)
        {
            CSelectPath dlgSp(this,pcHost);
            if (dlgSp.DoModal()==IDOK)
            {
            }
        }
        else
        {
            MessageBox("远程主机没有共享资源!","找不到共享资源",MB_OK|MB_ICONINFORMATION);
        }
        delete pShareTmp;
        delete pcHost;
        delete szWideIp;

微软MSDN网站上搜索不到相关的资料,求网友们回答。

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 66
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2

void EnumShareResources()
{
//PSHARE_INFO_1 pShareTmp=NULL,pShareBuffer=NULL;
PSHARE_INFO_0 pShareTmp=NULL,pShareBuffer=NULL;
NET_API_STATUS netApiStat=ERROR_SUCCESS;
DWORD dwEr=0,dwTr=0,dwResume=0,i=0,dwEnumOpenStat=0,dwEnumEnumStat=0;
char* pcHost=(char*)calloc(64,sizeof(char));
LPWSTR szWideIp=(LPWSTR)calloc(32,sizeof(WCHAR));
BOOL bFind=FALSE;
sprintf(pcHost,"%d.%d.%d.%d",192,168,10,183);
//GetHostNameByIp(pcHost);
//i=MultiByteToWideChar(CP_ACP,0,pcIp,-1,NULL,0);
MultiByteToWideChar(CP_ACP,0,pcHost,-1,szWideIp,64);
memcpy(pcHost,szWideIp,64);
do
{
//netApiStat=NetShareEnum(pcHost,1,(LPBYTE*)&pShareBuffer,-1,&dwEr,&dwTr,&dwResume);
netApiStat=NetShareEnum(pcHost,0,(LPBYTE*)&pShareBuffer,-1,&dwEr,&dwTr,&dwResume);
if (netApiStat==ERROR_MORE_DATA||netApiStat==ERROR_SUCCESS)
{
pShareTmp=pShareBuffer;
for (i=0;i<dwEr;i++)
{
//wprintf(L"%-20s%-8d%-20s",pShareTmp->shi1_netname,pShareTmp->shi1_type,pShareTmp->shi1_remark);
wprintf(L"%20s",pShareTmp->shi0_netname);
printf("\r\n");
pShareTmp++;
}
NetApiBufferFree(pShareTmp);
}

} while (netApiStat==ERROR_MORE_DATA);
}

知道SHARE_INFO_1与SHARE_INFO_502各自不同的用途之后解决了。
2013-3-1 00:22
0
游客
登录 | 注册 方可回帖
返回
//