ABE settings script for Windows Server fileserver shared files

Source: Internet
Author: User

Param([string]$rootPath)$Source= @"Using system;using system.collections.generic;using system.runtime.interopservices;using System.Text;public enum    share_type:uint {stype_disktree = 0x00000000,//Disk Drive STYPE_PRINTQ = 0x00000001,//Print Queue     Stype_device = 0x00000002,//Communications DEVICE STYPE_IPC = 0x00000003,//interprocess Communications Stype_special = 0x80000000,//Special share types (c $, admin$, ipc$, etc) Stype_temporary = 0x40000000//Te Mporary share}public enum Share_returnvalue:int {nerr_success = 0, error_access_denied = 5, ER Ror_not_enough_memory = 8, Error_invalid_parameter =, Error_invalid_level = 124,//unimplemented level for I    NFO error_more_data = 234, Nerr_buftoosmall = 2123,//The API return buffer is too small. Nerr_netnamenotfound = 2310//This shared resource does not exist.} [System.flags]public enum shi1005_flags {shi1005_flags_dfs = 0X0001,//part of a Dfs tree (cannot be set) Shi1005_flags_dfs_root = 0x0002,//ROOT of a DFS tr EE (cannot be set) Shi1005_flags_restrict_exclusive_opens = 0x0100,//Disallow EXCLUSIVE File Open Shi1005_fla      Gs_force_shared_delete = 0x0200,//Open files can be force deleted shi1005_flags_allow_namespace_caching = 0x0400,//clients can cache the namespace Shi1005_flags_access_based_directory_enum = 0x0800,//Only Directori Es for which a user have file_list_directory would be listed shi1005_flags_force_levelii_oplock = 0x1000,//Pre Vents Exclusive Caching Shi1005_flags_enable_hash = 0x2000,//used for server side support for peer Caching Shi1005_flags_enable_ca = 0X4000//used for Clustered Shares}public class NetApi32 {/ /********** Structures **********//share_info_502 [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; }//share_info_1005 [StructLayout (layoutkind.sequential)] public struct share_info_1005 {public in    T32 Shi1005_flags; } private class Unmanaged {//netsharegetinfo [DllImport ("Netapi32.dll", Setlasterror=true)] internal static extern int NetShareGetInfo ([MarshalAs (UNMANAGEDTYPE.LPWSTR)] string serverName, [Ma        Rshalas (UNMANAGEDTYPE.LPWSTR)] string netname, Int32 level, ref IntPtr BUFPTR); Netsharesetinfo [DllImport ("Netapi32.dll", Setlasterror=true)] internal static extern int Netsharesetinfo (string servername, String netname, Int32 le    Vel, ref IntPtr buf, out UInt32 parm_err);        }//* * * * * * * * * Functions public static share_info_502 netsharegetinfo_502 (String ServerName, String ShareName) {        Int32 level = 502;        IntPtr lshareinfo = IntPtr.Zero;        share_info_502 shi502_info = new share_info_502 ();        Int32 result = Unmanaged.netsharegetinfo (ServerName, ShareName, level, ref lshareinfo); if ((share_returnvalue) result = = share_returnvalue.nerr_success) {Shi502_info = (share_info_502) marshal.ptrtost        Ructure (Lshareinfo, typeof (share_info_502)); } else {throw new Exception ("Unable to get 502 structure.FunctionReturned:"+ (Share_returnvalue) result);    } return shi502_info;        public static share_info_1005 netsharegetinfo_1005 (String ServerName, String ShareName) {Int32 level = 1005;        IntPtr lshareinfo = IntPtr.Zero;        share_info_1005 shi1005_info = new share_info_1005 ();        Int32 result = Unmanaged.netsharegetinfo (ServerName, ShareName, level, ref lshareinfo); if ((share_returnvalue) result = = share_returnvalue.nerr_success) {Shi1005_info = (share_info_1005) Marshal.ptrto        Structure (Lshareinfo, typeof (share_info_1005)); } else {throw new Exception ("Unable to get 1005 structure.FunctionReturned:"+ (Share_returnvalue) result);    } return shi1005_info;  } public static int netsharesetinfo_1005 (string ServerName, String ShareName, Int32 shi1005_flags) {Int32 level        = 1005;        UInt32 err;        share_info_1005 shi1005_info = new share_info_1005 ();        Shi1005_info.shi1005_flags = Shi1005_flags;        IntPtr lshareinfo = gchandle.tointptr (GCHandle.Alloc (shi1005_info));        Int32 result = Unmanaged.netsharesetinfo (ServerName, ShareName, level, ref lshareinfo, out err);    return result; }}"@#[netapi32]::netsharesetinfo_502 ("MyServer", "Mysharename")Add-type-typedefinition$Source-Language CSharp$SmbShare= new-Object NETAPI32$SmbShare. Netsharesetinfo_1005 ($rootPath)#useage. \netsharesetinfo.ps1-rootpath"\\PXXXXXXXXXXXX\share" 

ABE settings script for Windows Server fileserver shared files

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.