Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5199,38 +5199,48 @@ internal static List<string> GetFileShares(string machine, bool ignoreHidden)
uint numEntries = 0;
uint totalEntries;
uint resumeHandle = 0;
int result = Interop.Windows.NetShareEnum(
machine,
level: 1,
out shBuf,
Interop.Windows.MAX_PREFERRED_LENGTH,
out numEntries,
out totalEntries,
ref resumeHandle);

var shares = new List<string>();
if (result == Interop.Windows.ERROR_SUCCESS || result == Interop.Windows.ERROR_MORE_DATA)
try
{
for (int i = 0; i < numEntries; ++i)
{
nint curInfoPtr = shBuf + (Marshal.SizeOf<SHARE_INFO_1>() * i);
SHARE_INFO_1 shareInfo = Marshal.PtrToStructure<SHARE_INFO_1>(curInfoPtr);
int result = Interop.Windows.NetShareEnum(
machine,
level: 1,
out shBuf,
Interop.Windows.MAX_PREFERRED_LENGTH,
out numEntries,
out totalEntries,
ref resumeHandle);

if ((shareInfo.type & Interop.Windows.STYPE_MASK) != Interop.Windows.STYPE_DISKTREE)
var shares = new List<string>();
if (result == Interop.Windows.ERROR_SUCCESS || result == Interop.Windows.ERROR_MORE_DATA)
{
for (int i = 0; i < numEntries; ++i)
{
continue;
}
nint curInfoPtr = shBuf + (Marshal.SizeOf<SHARE_INFO_1>() * i);
SHARE_INFO_1 shareInfo = Marshal.PtrToStructure<SHARE_INFO_1>(curInfoPtr);

if (ignoreHidden && shareInfo.netname.EndsWith('$'))
{
continue;
if ((shareInfo.type & Interop.Windows.STYPE_MASK) != Interop.Windows.STYPE_DISKTREE)
{
continue;
}

if (ignoreHidden && shareInfo.netname.EndsWith('$'))
{
continue;
}

shares.Add(shareInfo.netname);
}
}

shares.Add(shareInfo.netname);
return shares;
}
finally
{
if (shBuf != nint.Zero)
{
Interop.Windows.NetApiBufferFree(shBuf);
}
}

return shares;
#endif
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#nullable enable

using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static unsafe partial class Windows
{

[LibraryImport("Netapi32.dll")]
internal static partial uint NetApiBufferFree(nint Buffer);
}
}
Loading