/// <summary>
 /// Tries to connect to the host specified. The connection is used WMI.
 /// </summary>
 /// <param name="target">Host to Connect</param>
 public void Connect(TargetInfo target)
 {
     try
     {
         Credentials credentials = target.IsLocalTarget() ? null : target.credentials;
         ConnectionOptions options = this.GetConnectionOptions(credentials);
         
         this.ConnectionScope = this.GetManagementScope(options, target.GetAddress());
     }
     catch (UnauthorizedAccessException unauthorizedAccessException)
     {
         string errorMessage = string.Format(INVALID_CREDENTIALS_ERROR_MESSAGE, target.GetAddress(), target.credentials.GetDomain(), target.credentials.GetUserName());
         throw new InvalidCredentialsException(target.credentials, errorMessage, unauthorizedAccessException);
     }
     catch (COMException comException)
     {
         string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), comException.Message);
         throw new CannotConnectToHostException(target, errorMessage, comException);
     }
     catch (Exception ex)
     {
         string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), ex.Message);
         throw new ProbeException(errorMessage, ex);
     }
 }
        /// <summary>
        /// Tries to connect to the specified host trought WMI.
        /// </summary>
        /// <param name="target">Host to Connect</param>
        public void Connect(TargetInfo target)
        {
            try
            {
                var targetAddress = target.GetAddress();
                var credentials   = target.IsLocalTarget() ? null : target.credentials;
                var options       = this.GetConnectionOptions(credentials);

                this.ConnectionScope = this.GetManagementScope(options, targetAddress);
            }
            catch (UnauthorizedAccessException unauthorizedAccessException)
            {
                var    credentials  = target.credentials;
                string errorMessage = string.Format(INVALID_CREDENTIALS_ERROR_MESSAGE, target.GetAddress(), credentials.GetDomain(), credentials.GetUserName() + " FullyQualified: '" + credentials.GetFullyQualifiedUsername());
                throw new InvalidCredentialsException(target.credentials, errorMessage, unauthorizedAccessException);
            }
            catch (COMException comException)
            {
                string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), comException.Message);
                throw new CannotConnectToHostException(target, errorMessage, comException);
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format(PROVIDER_CONNECTING_ERROR_MESSAGE, target.GetAddress(), ex.Message);
                throw new ProbeException(errorMessage, ex);
            }
        }
Beispiel #3
0
        public static ConnectionOptions CreateConnectionOptions(TargetInfo target)
        {
            var connectionOptions = GetConnectionOptions();
            if (!target.IsLocalTarget())
            {
                connectionOptions.Username = target.credentials.GetFullyQualifiedUsername();
                connectionOptions.Password = target.credentials.GetPassword();
            }

            return connectionOptions;
        }
        public static ConnectionOptions CreateConnectionOptions(TargetInfo target)
        {
            var connectionOptions = GetConnectionOptions();

            if (!target.IsLocalTarget())
            {
                connectionOptions.Username = target.credentials.GetFullyQualifiedUsername();
                connectionOptions.Password = target.credentials.GetPassword();
            }

            return(connectionOptions);
        }
Beispiel #5
0
        private void ConnectToTarget(TargetInfo targetInfo)
        {
            if (targetInfo.IsLocalTarget())
            {
                return;
            }

            try
            {
                string remoteUNC = string.Format(@"\\{0}", targetInfo.GetAddress());
                string userName  = targetInfo.IsThereCredential() ? targetInfo.credentials.GetFullyQualifiedUsername() : string.Empty;
                string password  = string.IsNullOrEmpty(userName) ? string.Empty : targetInfo.credentials.GetPassword();

                WinNetUtils.connectToRemote(remoteUNC, userName, password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void ConnectToTarget(TargetInfo targetInfo)
        {
            if (targetInfo.IsLocalTarget())
                return;
            
            try
            {
                string remoteUNC = string.Format(@"\\{0}", targetInfo.GetAddress());
                string userName = targetInfo.IsThereCredential() ? targetInfo.credentials.GetFullyQualifiedUsername() : string.Empty;
                string password = string.IsNullOrEmpty(userName) ? string.Empty : targetInfo.credentials.GetPassword();

                WinNetUtils.connectToRemote(remoteUNC, userName, password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }