Пример #1
0
        public NTShare CreateShare(string name, string description, WinAPI.NETAPI32.SHARE_TYPE type, string path)
        {
            var newShare = new WinAPI.NETAPI32.SHARE_INFO_502 {
                shi502_netname = name,
                shi502_remark  = description,
                shi502_type    = (uint)type,
                shi502_path    = path
            };
            uint paramErr;
            var  result = WinAPI.NETAPI32.NetShareAdd(this.Host, 502, ref newShare, out paramErr);

            if (result != 0)
            {
                throw new NetApiException(
                          result,
                          "Unable to create local share '{0}' on host '{1}'",
                          name,
                          Host
                          );
            }

            var share = new NTShare {
                Host = Host,
                Name = name
            };

            share.Refresh();
            return(share);
        }
Пример #2
0
        public override void Update()
        {
            var shareInfo = new WinAPI.NETAPI32.SHARE_INFO_502 {
                shi502_current_uses        = (uint)CurrentUses,
                shi502_max_uses            = (uint)MaxUses,
                shi502_netname             = Name,
                shi502_passwd              = Password,
                shi502_path                = ServerPath,
                shi502_permissions         = (uint)Permissions,
                shi502_remark              = Description,
                shi502_reserved            = (uint)Reserved,
                shi502_security_descriptor = SecurityDescriptor,
                shi502_type                = (uint)Type
            };


            #region Get security descriptor

            // WinAPI.NETAPI32.SECURITY_DESCRIPTOR secDescriptor;
            //byte[] buffer = new byte[SecurityDescriptor.BinaryLength];
            //SecurityDescriptor.GetBinaryForm(buffer, 0);
            //shareInfo.shi502_security_descriptor = (WinAPI.NETAPI32.SECURITY_DESCRIPTOR)buffer;

            #endregion

            uint parmError = 0;

            var result = WinAPI.NETAPI32.NetShareSetInfo(
                this.NTCompatibleHostName,
                this.Name,
                502,
                ref shareInfo,
                out parmError
                );

            if (result != WinAPI.NETAPI32.NET_API_STATUS.NERR_Success)
            {
                throw new NetApiException(
                          result,
                          "Unable to update share '{0}' on host '{1}'.",
                          Name,
                          Host
                          );
            }
        }