我正在编写一些软件,我需要获取网络共享文件夹列表。我根据这篇文章做了所有的事情 http://www.codeproject.com/Articles/2939/Network-Shares-and-UNC-paths 并且方法NetShareEnum返回1702,并且不返回任何文件夹。
来自文章的编译样本工作正常,我试图通过Resharper解散它,但它也返回1702结果:
protected static void EnumerateSharesNT(string server, ShareCollection shares)
{
int dwLevel = 2;
int hResume = 0;
IntPtr zero = IntPtr.Zero;
try
{
int num2;
int num3;
**int num4 = NetShareEnum(server, dwLevel, out zero, -1, out num2, out num3, ref hResume);**
if (5 == num4)
{
dwLevel = 1;
num4 = NetShareEnum(server, dwLevel, out zero, -1, out num2, out num3, ref hResume);
}
if ((num4 == 0) && (num2 > 0))
{
Type t = (2 == dwLevel) ? typeof(SHARE_INFO_2) : typeof(SHARE_INFO_1);
int num6 = Marshal.SizeOf(t);
int num7 = 0;
for (int i = zero.ToInt32(); num7 < num2; i += num6)
{
IntPtr ptr = new IntPtr(i);
if (1 == dwLevel)
{
SHARE_INFO_1 share_info_ = (SHARE_INFO_1)Marshal.PtrToStructure(ptr, t);
shares.Add(share_info_.NetName, string.Empty, share_info_.ShareType, share_info_.Remark);
}
else
{
SHARE_INFO_2 share_info_2 = (SHARE_INFO_2)Marshal.PtrToStructure(ptr, t);
shares.Add(share_info_2.NetName, share_info_2.Path, share_info_2.ShareType, share_info_2.Remark);
}
num7++;
}
}
}
finally
{
if (IntPtr.Zero != zero)
{
NetApiBufferFree(zero);
}
}
}
服务器是输入字符串,例如&#34; \ 192.168.1.69&#34;