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.
[StructLayout(LayoutKind.Sequential)]
private struct SHARE_INFO_502
{
[MarshalAs(UnmanagedType.LPWStr)] public string shi502_netname;
public SHARE_TYPE shi502_type;
[MarshalAs(UnmanagedType.LPWStr)] public string shi502_remark;
public Int32 shi502_permissions;
public Int32 shi502_max_uses;
public Int32 shi502_current_uses;
[MarshalAs(UnmanagedType.LPWStr)] public string shi502_path;
[MarshalAs(UnmanagedType.LPWStr)] public string shi502_passwd;
public Int32 shi502_reserved;
public IntPtr shi502_security_descriptor;
}
#Region "SHARE_TYPE Enumeration Definition"
' <summary>Type of share</summary>
Public Enum ShareType
' <summary>Disk Share</summary>
Disk = 0
' <summary>Printer Share</summary>
Printer = 1
' <summary>Device Share</summary>
Device = 2
' <summary>IPC Share</summary>
IPC = 3
' <summary>Special Share</summary>
' <remarks>
' Add this value to one of the above values
' to get an Administrative Share of that type
' </remarks>
Temporary = &H40000000
Special = &H80000000
End Enum
#End Region
Notes:
[2004-06-11]
VB Def and Sample code added by RACKLEY
#Region "SHARE_INFO_2 Structure Definition"
<StructLayout(LayoutKind.Sequential)> _
Public Structure SHARE_INFO_2
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_netname As String
<MarshalAs(UnmanagedType.U4)> _
Public shi2_type As ShareType
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_remark As String
<MarshalAs(UnmanagedType.U4)> _
Public shi2_permissions As SharePermissions
<MarshalAs(UnmanagedType.U4)> _
Public shi2_max_uses As Integer
<MarshalAs(UnmanagedType.U4)> _
Public shi2_current_uses As Integer
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_path As String
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_passwd As String
C# Sample Code:
Public Sub New( _
ByVal netName As String, _
ByVal type As ShareType, _
ByVal remark As String, _
ByVal maxUses As Integer, _
ByVal path As String, _
ByVal permissions As SharePermissions, _
ByVal passwd As String)
string shareName = "testshare";
string shareDesc = "This is a test share kekelar2000";
string path = @"C:\MyShareDirectory"; // do not append comma, it'll fail
shi2_netname = netName
shi2_type = type
shi2_remark = remark
shi2_permissions = permissions
shi2_max_uses = maxUses
shi2_current_uses = 0
shi2_path = path
shi2_passwd = passwd
End Sub
End Structure
#End Region
Notes:
[2004-06-11]
VB Def and Sample code added by RACKLEY
VB Def and enums updated by SPASCOE
Tips & Tricks:
This function will take as it's third parameter, a number of structures. The second parameter defines which level the third parameter structure is. Acceptable structures are SHARE_INFO_2, SHARE_INFO_502, and under Windows 9x/ME, SHARE_INFO_50.
C# Sample Code:
string shareName = "testshare";
string shareDesc = "This is a test share kekelar2000";
string path = @"C:\MyShareDirectory"; // do not append comma, it'll fail
SHARE_INFO_502 info = new SHARE_INFO_502();
info.shi502_netname = shareName;
info.shi502_type = SHARE_TYPE.STYPE_DISKTREE;
info.shi502_remark = shareDesc;
info.shi502_permissions = 0; // ignored for user-level security
info.shi502_max_uses = -1;
info.shi502_current_uses = 0; // ignored for set
info.shi502_path = path;
info.shi502_passwd = null; // ignored for user-level security
info.shi502_reserved = 0;
info.shi502_security_descriptor = IntPtr.Zero;
uint error = 0;
uint result = NetShareAdd(server, 502, ref info, out error);
VB.NET Sample Code:
Dim shi2 As SHARE_INFO_2
' Populate the structure with information
shi2.shi2_netname = sharename" ' share name
shi2.shi2_type = ShareType.Disk ' disk drive
shi2.shi2_type = STYPE_DISKTREE ' disk drive
shi2.shi2_remark = "" ' share comment
shi2.shi2_permissions = SharePermissions.ACCESS_NONE
shi2.shi2_permissions = 0
shi2.shi2_max_uses = -1 ' unlimited
shi2.shi2_current_uses = 0
shi2.shi2_path = "c:\myshare"
shi2.shi2_passwd = Nothing ' no password
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).