[ StructLayout( LayoutKind.Sequential )]
public struct SHARE_INFO_502
{
[MarshalAs(UnmanagedType.LPWStr)]
public string shi502_netname;
public uint 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;
public IntPtr shi502_passwd;
public Int32 shi502_reserved;
public IntPtr shi502_security_descriptor;
}
[DllImport("Netapi32.dll")]
public static extern int NetShareAdd([MarshalAs(UnmanagedType.LPWStr)]string strServer, Int32 dwLevel, IntPtr buf, IntPtr parm_err);
//删除共享
[System.Runtime.InteropServices.DllImport("netapi32")]
private static extern int NetShareDel([MarshalAs(UnmanagedType.LPWStr)]string strServer, [MarshalAs(UnmanagedType.LPWStr)]string ShareName, int dword);
//共享类型
private const long STYPE_ALL = -1;
private const long STYPE_DISKTREE = 0;
private const long STYPE_PRINTQ = 1;
private const long STYPE_DEVICE = 2;
private const long STYPE_IPC = 3;
private const long STYPE_SPECIAL = 0X80000000;
//权限
private const long ACCESS_READ = 0X1;
private const long ACCESS_WRITE = 0X2;
private const long ACCESS_CREATE = 0X4;
private const long ACCESS_EXEC = 0X8;
private const long ACCESS_DELETE = 0X10;
private const long ACCESS_ATRIB = 0X20;
private const long ACCESS_PERM = 0X40;
private const long ACCESS_ALL = ACCESS_READ | ACCESS_WRITE | ACCESS_CREATE | ACCESS_EXEC | ACCESS_DELETE | ACCESS_ATRIB | ACCESS_PERM;
//出错信息
private const int ERROR_ACCESS_DENIED = 5;
private const int ERROR_INVALID_LEVEL = 124;
private const int ERROR_INVALID_NAME = 123;// dderror
private const int DNS_ERROR_INVALID_NAME = ERROR_INVALID_NAME;
private const int ERROR_INVALID_PARAMETER = 87;// dderror
private const int NERR_BASE = 2100;
private const int NERR_DuplicateShare = (NERR_BASE+18); /* The name has already been shared. */
//共享信息
private struct SHARE_INFO_2
{
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_netname ; //共享名
public long shi2_type ; //类型
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_remark ; //备注
public long shi2_permissions ; //权限
public long shi2_max_uses ; //最大用户
public string shi2_current_uses ; //
public string shi2_path ; //路径
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_pswd ; //密码
}