Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
NetShareEnum (netapi32)
.
C# Signature:
[DllImport("Netapi32.dll", CharSet=CharSet.Unicode)]
private static extern int NetShareEnum(
StringBuilder ServerName,
int level,
ref IntPtr bufPtr,
uint prefmaxlen,
ref int entriesread,
ref int totalentries,
ref int resume_handle
);
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
VB Signature:
<DllImport("Netapi32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function NetShareEnum( _
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
End Function
User-Defined Types:
if you use C# Sample code;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct SHARE_INFO_0
{
public string shi0_netname;
}
const uint MAX_PREFERRED_LENGTH = 0xFFFFFFFF;
const int NERR_Success = 0;
Notes:
[28-06-2007]
VB Enumeration Function Added by JustAl
[2006-07-05]
VB Alternate Signature code added by KRONOS
[2004-06-11]
VB Def and Sample code added by RACKLEY
[2004-08-31]
C# Def and Sample code added by K.MORONO
''' <summary>
''' Enumerates the shares on Windows NT
''' </summary>
''' <param name="server">The server name</param>
''' <param name="shares">The ShareCollection</param>
Protected Shared Sub EnumerateSharesNT(ByVal server As String, ByVal shares As ShareCollection)
Dim level As Integer = 2
Dim entriesRead As Integer, totalEntries As Integer, nRet As Integer, hResume As Integer = 0
Dim pBuffer As IntPtr = IntPtr.Zero
If ERROR_ACCESS_DENIED = nRet Then
'Need admin for level 2, drop to level 1
level = 1
nRet = NetShareEnum(server, level, pBuffer, -1, entriesRead, totalEntries, _
hResume)
End If
If NO_ERROR = nRet AndAlso entriesRead > 0 Then
Dim t As Type = IIf((2 = level), GetType(SHARE_INFO_2), GetType(SHARE_INFO_1))
Dim offset As Integer = Marshal.SizeOf(t)
Dim i As Integer = 0, lpItem As Integer = pBuffer.ToInt32()
While i < entriesRead
Dim pItem As New IntPtr(lpItem)
If 1 = level Then
Dim si As SHARE_INFO_1 = DirectCast(Marshal.PtrToStructure(pItem, t), SHARE_INFO_1)
shares.Add(si.NetName, "Access Denied", si.ShareType, si.Remark)
Else
Dim si As SHARE_INFO_2 = DirectCast(Marshal.PtrToStructure(pItem, t), SHARE_INFO_2)
shares.Add(si.NetName, si.Path, si.ShareType, si.Remark)
End If
i += 1
lpItem += offset
End While
End If
Finally
' Clean up buffer allocated by system
If IntPtr.Zero <> pBuffer Then
NetApiBufferFree(pBuffer)
End If
End Try
End Sub
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)
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)
[C#]
PUT TextBox control,ListBox control and Button control on your Form.
Frees the memory allocated by network management functions.
6/21/2016 8:26:32 AM - -63.226.251.37
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).