C # network sharing

Source: Internet
Author: User

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.