Esempio n. 1
0
 protected override void ProcessRecord()
 {
     if (this._newName == null || (int)this._computerName.Length == 1)
     {
         ConnectionOptions connectionOption = new ConnectionOptions();
         connectionOption.Authentication   = AuthenticationLevel.PacketPrivacy;
         connectionOption.Impersonation    = ImpersonationLevel.Impersonate;
         connectionOption.EnablePrivileges = true;
         ConnectionOptions  connectionOption1 = connectionOption;
         EnumerationOptions enumerationOption = new EnumerationOptions();
         enumerationOption.UseAmendedQualifiers = true;
         enumerationOption.DirectRead           = true;
         EnumerationOptions enumerationOption1 = enumerationOption;
         ObjectQuery        objectQuery        = new ObjectQuery("select * from Win32_ComputerSystem");
         int num = this._joinDomainflags;
         if (this._newName != null && base.ParameterSetName == "Domain")
         {
             AddComputerCommand addComputerCommand = this;
             addComputerCommand._joinDomainflags = addComputerCommand._joinDomainflags | 0x100;
         }
         try
         {
             string[] strArrays = this._computerName;
             for (int i = 0; i < (int)strArrays.Length; i++)
             {
                 string str  = strArrays[i];
                 string str1 = this.ValidateComputerName(str, this._newName != null);
                 if (str1 != null)
                 {
                     bool flag = str1.Equals("localhost", StringComparison.OrdinalIgnoreCase);
                     if (!flag)
                     {
                         this.DoAddComputerAction(str1, this._newName, false, connectionOption1, enumerationOption1, objectQuery);
                     }
                     else
                     {
                         if (!this._containsLocalHost)
                         {
                             this._containsLocalHost = true;
                         }
                         this._newNameForLocalHost = this._newName;
                     }
                 }
             }
         }
         finally
         {
             if (this._newName != null && base.ParameterSetName == "Domain")
             {
                 this._joinDomainflags = num;
             }
         }
         return;
     }
     else
     {
         this.WriteErrorHelper(ComputerResources.CannotRenameMultipleComputers, "CannotRenameMultipleComputers", this._newName, ErrorCategory.InvalidArgument, false, new object[0]);
         return;
     }
 }
Esempio n. 2
0
        private string ValidateComputerName(string computer, bool validateNewName)
        {
            IPAddress pAddress = null;
            string    str;
            object    obj;
            string    str1 = null;

            if (computer.Equals(".", StringComparison.OrdinalIgnoreCase) || computer.Equals("localhost", StringComparison.OrdinalIgnoreCase) || computer.Equals(this._shortLocalMachineName, StringComparison.OrdinalIgnoreCase) || computer.Equals(this._fullLocalMachineName, StringComparison.OrdinalIgnoreCase))
            {
                str1 = "localhost";
            }
            else
            {
                bool flag = false;
                try
                {
                    flag = IPAddress.TryParse(computer, out pAddress);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    CommandProcessorBase.CheckForSevereException(exception);
                }
                try
                {
                    string hostName = Dns.GetHostEntry(computer).HostName;
                    if (hostName.Equals(this._shortLocalMachineName, StringComparison.OrdinalIgnoreCase) || hostName.Equals(this._fullLocalMachineName, StringComparison.OrdinalIgnoreCase))
                    {
                        str1 = "localhost";
                    }
                    else
                    {
                        str1 = computer;
                    }
                    goto Label0;
                }
                catch (Exception exception3)
                {
                    Exception exception2 = exception3;
                    CommandProcessorBase.CheckForSevereException(exception2);
                    if (flag)
                    {
                        str1 = computer;
                        goto Label0;
                    }
                    else
                    {
                        object[] message = new object[2];
                        message[0] = computer;
                        message[1] = exception2.Message;
                        this.WriteErrorHelper(ComputerResources.CannotResolveComputerName, "AddressResolutionException", computer, ErrorCategory.InvalidArgument, false, message);
                        str = null;
                    }
                }
                return(str);
            }
Label0:
            bool flag1 = str1.Equals("localhost", StringComparison.OrdinalIgnoreCase);

            if (!validateNewName || this._newName == null || ComputerWMIHelper.IsComputerNameValid(this._newName))
            {
                return(str1);
            }
            else
            {
                AddComputerCommand addComputerCommand = this;
                string             invalidNewName     = ComputerResources.InvalidNewName;
                string             str2 = "InvalidNewName";
                string             str3 = this._newName;
                int      num            = 5;
                int      num1           = 0;
                object[] objArray       = new object[2];
                object[] objArray1      = objArray;
                int      num2           = 0;
                if (flag1)
                {
                    obj = this._shortLocalMachineName;
                }
                else
                {
                    obj = str1;
                }
                objArray1[num2] = obj;
                objArray[1]     = this._newName;
                addComputerCommand.WriteErrorHelper(invalidNewName, str2, str3, (ErrorCategory)num, num1 == 1 ? true : false, objArray);
                return(null);
            }
        }
Esempio n. 3
0
 protected override void BeginProcessing()
 {
     if (base.ParameterSetName == "Domain")
     {
         if ((this._joinOptions & JoinOptions.PasswordPass) != 0 && (this._joinOptions & JoinOptions.UnsecuredJoin) == 0)
         {
             object[] str = new object[2];
             str[0] = JoinOptions.PasswordPass.ToString();
             str[1] = JoinOptions.UnsecuredJoin.ToString();
             this.WriteErrorHelper(ComputerResources.InvalidJoinOptions, "InvalidJoinOptions", this._joinOptions, ErrorCategory.InvalidArgument, true, str);
         }
         if ((this._joinOptions & JoinOptions.AccountCreate) != 0)
         {
             AddComputerCommand addComputerCommand = this;
             addComputerCommand._joinDomainflags = addComputerCommand._joinDomainflags | 2;
         }
         if ((this._joinOptions & JoinOptions.Win9XUpgrade) != 0)
         {
             AddComputerCommand addComputerCommand1 = this;
             addComputerCommand1._joinDomainflags = addComputerCommand1._joinDomainflags | 16;
         }
         if ((this._joinOptions & JoinOptions.UnsecuredJoin) != 0)
         {
             AddComputerCommand addComputerCommand2 = this;
             addComputerCommand2._joinDomainflags = addComputerCommand2._joinDomainflags | 64;
         }
         if ((this._joinOptions & JoinOptions.PasswordPass) != 0)
         {
             AddComputerCommand addComputerCommand3 = this;
             addComputerCommand3._joinDomainflags = addComputerCommand3._joinDomainflags | 128;
         }
         if ((this._joinOptions & JoinOptions.DeferSPNSet) != 0)
         {
             AddComputerCommand addComputerCommand4 = this;
             addComputerCommand4._joinDomainflags = addComputerCommand4._joinDomainflags | 0x100;
         }
         if ((this._joinOptions & JoinOptions.JoinWithNewName) != 0)
         {
             AddComputerCommand addComputerCommand5 = this;
             addComputerCommand5._joinDomainflags = addComputerCommand5._joinDomainflags | 0x400;
         }
         if ((this._joinOptions & JoinOptions.JoinReadOnly) != 0)
         {
             AddComputerCommand addComputerCommand6 = this;
             addComputerCommand6._joinDomainflags = addComputerCommand6._joinDomainflags | 0x800;
         }
         if ((this._joinOptions & JoinOptions.InstallInvoke) != 0)
         {
             AddComputerCommand addComputerCommand7 = this;
             addComputerCommand7._joinDomainflags = addComputerCommand7._joinDomainflags | 0x40000;
         }
         if (this._unsecure)
         {
             AddComputerCommand addComputerCommand8 = this;
             addComputerCommand8._joinDomainflags = addComputerCommand8._joinDomainflags | 192;
         }
         if (this._server != null)
         {
             try
             {
                 Dns.GetHostEntry(this._server);
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 CommandsCommon.CheckForSevereException(this, exception);
                 object[] objArray = new object[1];
                 objArray[0] = this._server;
                 this.WriteErrorHelper(ComputerResources.CannotResolveServerName, "AddressResolutionException", this._server, ErrorCategory.InvalidArgument, true, objArray);
             }
             this._domainName = string.Concat(this._domainName, "\\", this._server);
         }
     }
 }