Exemple #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;
            var result = ChoMpr.WNetCancelConnection2(_networkShareName, ChoMpr.CONNECT_UPDATE_PROFILE, true);

            if (result != 0 && TraceErrors)
            {
                ChoTrace.Error(new ChoWin32Exception(result, "Error disconnecting to '{0}' remote share".FormatString(_networkShareName)));
            }
        }
Exemple #2
0
        public ChoNetworkShare(string networkShareName, NetworkCredential credentials)
        {
            ChoGuard.ArgumentNotNullOrEmpty(networkShareName, "NetworkShareName");
            ChoGuard.ArgumentNotNull(credentials, "NetworkCredentials");

            _networkShareName = networkShareName;

            var netResource = new NetResource()
            {
                Scope = ResourceScope.Context, ResourceType = ResourceType.Disk, DisplayType = ResourceDisplaytype.Share, RemoteName = _networkShareName
            };
            var result = ChoMpr.WNetAddConnection2(netResource, credentials.Password, @"{1}\{0}".FormatString(credentials.UserName, credentials.Domain), ChoMpr.CONNECT_UPDATE_PROFILE);

            if (result != 0)
            {
                throw new ChoWin32Exception(result, "Error connecting to '{0}' remote share".FormatString(_networkShareName));
            }
        }