[Csharp]
<Pre name = "code" class = "csharp"> using System;
Using System. Runtime. InteropServices;
Namespace ConApp
{
Class remote1_dir
{
[DllImport ("Netapi32.dll", CharSet = CharSet. Unicode)]
Private static extern uint netmask add (
[Financialas (UnmanagedType. LPWStr)] string strServer,
Int32 dwLevel,
Ref performance_info_502 buf,
Out uint parm_err
);
[DllImport ("Netapi32.dll", CharSet = CharSet. Unicode)]
Private static extern uint net1_del (string host, string shareName, int reserved );
Public remote1_dir ()
{
}
Public uint setincludir (string host, string dir, string shareName, string includesc)
{
SHARE_INFO_502 info = new SHARE_INFO_502 ();
Info. shi502_netname = shareName;
Info. shi502_type = pai_type.stype_disktree;
Info. shi502_remark = includesc;
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 = dir;
Info. shi502_passwd = null; // ignored for user-level security
Info. shi502_reserved = 0;
Info. shi502_security_descriptor = IntPtr. Zero;
Uint error = 0;
Return netmask add (host, 502, ref info, out error );
}
Public uint DeleteShareDir (string host, string shareName)
{
Return netdomaindel (host, shareName, 0 );
}
Private enum NetError: uint
{
NERR_Success = 0,
Nerr_base= 2100,
NERR_UnknownDevDir = (NERR_BASE + 16 ),
NERR_DuplicateShare = (NERR_BASE + 18 ),
NERR_BufTooSmall = (NERR_BASE + 23 ),
} Www.2cto.com
Private enum 1__type: uint
{
STYPE_DISKTREE = 0,
STYPE_PRINTQ = 1,
STYPE_DEVICE = 2,
STYPE_IPC = 3,
STYPE_TEMPORARY = 0x40000000,
STYPE_SPECIAL = 0x80000000,
}
[StructLayout (LayoutKind. Sequential)]
Private struct pai_info_502
{
[Financialas (UnmanagedType. LPWStr)]
Public string shi502_netname;
Public performance_type shi502_type;
[Financialas (UnmanagedType. LPWStr)]
Public string shi502_remark;
Public Int32 shi502_permissions;
Public Int32 shi502_max_uses;
Public Int32 shi502_current_uses;
[Financialas (UnmanagedType. LPWStr)]
Public string shi502_path;
[Financialas (UnmanagedType. LPWStr)]
Public string shi502_passwd;
Public Int32 shi502_reserved;
Public IntPtr shi502_security_descriptor;
}
}
}
Author: wmingcsharp