netshareenum (netapi32)
Last changed: -50.207.245.42

.
Summary
TODO - a short description

C# Signature:

[DllImport("netapi32.dll", SetLastError=true)]
static extern TODO NetShareEnum(TODO);

VB Signature:

Declare Unicode Function NetShareEnum Lib "netapi32.dll" _
            (ByVal ServerName As StringBuilder, _
            ByVal level As Integer, _
            ByRef BufPtr As IntPtr, _
            ByVal prefmaxbufferlen As Integer, _
            ByRef entriesread As Integer, _
            ByRef totalentries As Integer, _
            ByRef resume_handle As Integer) As Integer

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Dim currentPtr As IntPtr
Dim BufPtr As IntPtr        'in
Dim dwEntriesread As Integer     'out
Dim dwTotalentries As Integer    'out
Dim dwResumehandle As Integer    'out
Dim nStructSize As Integer
Dim shi2 As SHARE_INFO_2
Dim cnt As Long         'share enumeration counter
Dim SvrNameBldr As New StringBuilder(ServerName)

retval = NetShareEnum(SvrNameBldr, 2, BufPtr, MAX_PREFERRED_LENGTH, dwEntriesread, dwTotalentries, dwResumehandle)

If retval = NERR_Success And retval <> ERROR_MORE_DATA Then
   currentPtr = BufPtr
   nStructSize = Marshal.SizeOf(GetType(SHARE_INFO_2))

   ' Enumerate over all shares on the server and find the any/all shares that point
   ' to c:\deletemeplease and delete those shares.
   For cnt = 0 To dwEntriesread - 1
     shi2 = Marshal.PtrToStructure(currentPtr, GetType(SHARE_INFO_2))
     If System.String.Compare(shi2.shi2_path, "c:\deletemeplease" True) = 0 Then
       DelRetVal = NetShareDel(ServerName, shi2.shi2_netname, 0)
     End If
     currentPtr = New IntPtr(currentPtr.ToInt32 + Marshal.SizeOf(GetType(SHARE_INFO_2)))
   Next

End If
Call NetApiBufferFree(BufPtr)

Alternative Managed API:

Do you know one? Please contribute it!

Documentation