请求大家帮助,学习SDK的Net Functions的使用方法(一定给分) 大家好,我最近在工作中需要使用WindowsAPI的Net Functions的哦一系列函数。由于英语阅读能力比较差,对于MSDN的东西只是一知半解。在编码过程中,一直无法正确使用诸如"NetShareGetInfo"以及"NetShareEnum"等一系列函数的使用方法。希望向各位大虾请教一下,如果能够提供比较详尽的源代码就更好了。多谢大家了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #define UNICODE#include <windows.h>#include <stdio.h>#include <lm.h>void wmain( int argc, TCHAR *lpszArgv[ ]){ PSHARE_INFO_502 BufPtr,p; NET_API_STATUS res; LPTSTR lpszServer = NULL; DWORD er=0,tr=0,resume=0, i; switch(argc) { case 2: lpszServer = lpszArgv[1]; break; default: printf("Usage: NetShareEnum <servername>\n"); return; } // // Print a report header. // printf("Share: Local Path: Uses: Descriptor:\n"); printf("---------------------------------------------------------------------\n"); // // Call the NetShareEnum function; specify level 502. // do // begin do { res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume); // // If the call succeeds, // if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA) { p=BufPtr; // // Loop through the entries; // print retrieved data. // for(i=1;i<=er;i++) { printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses); // // Validate the value of the // shi502_security_descriptor member. // if (IsValidSecurityDescriptor(p->shi502_security_descriptor)) printf("Yes\n"); else printf("No\n"); p++; } // // Free the allocated buffer. // NetApiBufferFree(BufPtr); } else printf("Error: %ld\n",res); } // Continue to call NetShareEnum while // there are more entries. // while (res==ERROR_MORE_DATA); // end do return;} 谢谢大家的支持。还希望了解函数NetShareGetInfo的使用方法。最好大部分Net Functions族里面的函数都想了解一下。 www.sysinternals.com上,有个开源的工具,ShareEnum,用到了你说的函数,看看它的示例代码吧。 谢谢DentistryDoctor的帮助。那个开源的东西已经下载了,我把相关的代码提取出来测试了一下,函数可以正常使用,但是出来的共享目录的名字只有第一个字母,后面的全都没有。遇上汉字的话就会显示乱码,不知道怎么回事,能请教一下吗。多谢。 用vc编译downloadmgr.idl时出错? 怎么样不重启电脑就让更新后的USB驱动生效? 如何把图片数据转化成Base64数据格式? CComboBox的SetFocus问题 请问哪里可以下载MSDN,最好是教育网上的 菜虫问:问题简单,在线等 在dialogbar中加入OCX控件后不可见 关于MFC的CLISTCTRL的问题~(基础问题) 响应ClistBox的LBN_SELCHANGE消息 按钮和文本框的句柄问题 richedit里能不能设置行数的阿? 用CImageList::GetImageInfo取某个bitmap的hbitmap怎么好像不管用?
#include <windows.h>
#include <stdio.h>
#include <lm.h>void wmain( int argc, TCHAR *lpszArgv[ ])
{
PSHARE_INFO_502 BufPtr,p;
NET_API_STATUS res;
LPTSTR lpszServer = NULL;
DWORD er=0,tr=0,resume=0, i; switch(argc)
{
case 2:
lpszServer = lpszArgv[1];
break;
default:
printf("Usage: NetShareEnum <servername>\n");
return;
}
//
// Print a report header.
//
printf("Share: Local Path: Uses: Descriptor:\n");
printf("---------------------------------------------------------------------\n");
//
// Call the NetShareEnum function; specify level 502.
//
do // begin do
{
res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
//
// If the call succeeds,
//
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p=BufPtr;
//
// Loop through the entries;
// print retrieved data.
//
for(i=1;i<=er;i++)
{
printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses);
//
// Validate the value of the
// shi502_security_descriptor member.
//
if (IsValidSecurityDescriptor(p->shi502_security_descriptor))
printf("Yes\n");
else
printf("No\n");
p++;
}
//
// Free the allocated buffer.
//
NetApiBufferFree(BufPtr);
}
else
printf("Error: %ld\n",res);
}
// Continue to call NetShareEnum while
// there are more entries.
//
while (res==ERROR_MORE_DATA); // end do
return;
}