protected override void BeginProcessing()
        {
            string str;

            if (!ComputerWMIHelper.SkipSystemRestoreOperationForARMPlatform(this))
            {
                ManagementScope managementScope = new ManagementScope("\\root\\default");
                managementScope.Connect();
                this.WMIClass       = new ManagementClass("SystemRestore");
                this.WMIClass.Scope = managementScope;
                string   str1      = Environment.ExpandEnvironmentVariables("%SystemDrive%");
                string[] strArrays = new string[2];
                strArrays[0] = str1;
                strArrays[1] = "\\";
                str1         = string.Concat(strArrays);
                if (!ComputerWMIHelper.ContainsSystemDrive(this._drive, str1))
                {
                    ArgumentException argumentException = new ArgumentException(StringUtil.Format(ComputerResources.NoSystemDrive, new object[0]));
                    base.WriteError(new ErrorRecord(argumentException, "EnableComputerNoSystemDrive", ErrorCategory.InvalidArgument, null));
                }
                else
                {
                    object[] objArray = new object[1];
                    objArray[0] = str1;
                    object[] objArray1 = objArray;
                    try
                    {
                        int num = Convert.ToInt32(this.WMIClass.InvokeMethod("Enable", objArray1), CultureInfo.CurrentCulture);
                        if (num.Equals(0) || num.Equals(0x420))
                        {
                            string[] strArrays1 = this._drive;
                            for (int i = 0; i < (int)strArrays1.Length; i++)
                            {
                                string str2 = strArrays1[i];
                                if (base.ShouldProcess(str2))
                                {
                                    if (str2.EndsWith("\\", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        str = str2;
                                    }
                                    else
                                    {
                                        str = string.Concat(str2, "\\");
                                    }
                                    if (ComputerWMIHelper.IsValidDrive(str))
                                    {
                                        if (!str.Equals(str1, StringComparison.OrdinalIgnoreCase))
                                        {
                                            object[] objArray2 = new object[1];
                                            objArray2[0] = str;
                                            object[] objArray3 = objArray2;
                                            num = Convert.ToInt32(this.WMIClass.InvokeMethod("Enable", objArray3), CultureInfo.CurrentCulture);
                                            if (num.Equals(0x6b5))
                                            {
                                                num = Convert.ToInt32(this.WMIClass.InvokeMethod("Enable", objArray3), CultureInfo.CurrentCulture);
                                            }
                                        }
                                        if (!num.Equals(0) && !num.Equals(0x420) && !num.Equals(0x6b5))
                                        {
                                            Exception exception = new ArgumentException(StringUtil.Format(ComputerResources.NotEnabled, str2));
                                            base.WriteError(new ErrorRecord(exception, "EnableComputerRestoreNotEnabled", ErrorCategory.InvalidOperation, null));
                                        }
                                    }
                                    else
                                    {
                                        Exception argumentException1 = new ArgumentException(StringUtil.Format(ComputerResources.InvalidDrive, str2));
                                        base.WriteError(new ErrorRecord(argumentException1, "EnableComputerRestoreInvalidDrive", ErrorCategory.InvalidData, null));
                                    }
                                }
                            }
                        }
                        else
                        {
                            ArgumentException argumentException2 = new ArgumentException(StringUtil.Format(ComputerResources.NotEnabled, str1));
                            base.WriteError(new ErrorRecord(argumentException2, "EnableComputerRestoreNotEnabled", ErrorCategory.InvalidOperation, null));
                        }
                    }
                    catch (ManagementException managementException1)
                    {
                        ManagementException managementException = managementException1;
                        if (managementException.ErrorCode.Equals(ManagementStatus.NotFound) || managementException.ErrorCode.Equals(ManagementStatus.InvalidClass))
                        {
                            ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(StringUtil.Format(ComputerResources.NotSupported, new object[0])), null, ErrorCategory.InvalidOperation, null);
                            base.WriteError(errorRecord);
                        }
                        else
                        {
                            ErrorRecord errorRecord1 = new ErrorRecord(managementException, "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                            base.WriteError(errorRecord1);
                        }
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        if (!string.IsNullOrEmpty(cOMException.Message))
                        {
                            ErrorRecord errorRecord2 = new ErrorRecord(cOMException, "COMException", ErrorCategory.InvalidOperation, null);
                            base.WriteError(errorRecord2);
                        }
                        else
                        {
                            Exception exception1 = new ArgumentException(StringUtil.Format(ComputerResources.SystemRestoreServiceDisabled, new object[0]));
                            base.WriteError(new ErrorRecord(exception1, "ServiceDisabled", ErrorCategory.InvalidOperation, null));
                        }
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the List of HotFixes installed on the Local Machine.
        /// </summary>
        protected override void ProcessRecord()
        {
            foreach (string computer in ComputerName)
            {
                bool            foundRecord = false;
                StringBuilder   queryString = new StringBuilder();
                ManagementScope scope       = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), _connectionOptions);
                scope.Connect();
                if (Id != null)
                {
                    queryString.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int i = 0; i <= Id.Length - 1; i++)
                    {
                        queryString.Append("HotFixID= '");
                        queryString.Append(Id[i].Replace("'", "\\'"));
                        queryString.Append("'");
                        if (i < Id.Length - 1)
                        {
                            queryString.Append(" Or ");
                        }
                    }

                    queryString.Append(")");
                }
                else
                {
                    queryString.Append("Select * from Win32_QuickFixEngineering");
                    foundRecord = true;
                }

                _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(queryString.ToString()));
                foreach (ManagementObject obj in _searchProcess.Get())
                {
                    if (Description != null)
                    {
                        if (!FilterMatch(obj))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        _inputContainsWildcard = true;
                    }

                    // try to translate the SID to a more friendly username
                    // just stick with the SID if anything goes wrong
                    string installed = (string)obj["InstalledBy"];
                    if (!string.IsNullOrEmpty(installed))
                    {
                        try
                        {
                            SecurityIdentifier secObj = new SecurityIdentifier(installed);
                            obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));
                        }
                        catch (IdentityNotMappedException)
                        {
                            // thrown by SecurityIdentifier.Translate
                        }
                        catch (SystemException)
                        {
                            // thrown by SecurityIdentifier.constr
                        }
                    }

                    WriteObject(obj);
                    foundRecord = true;
                }

                if (!foundRecord && !_inputContainsWildcard)
                {
                    Exception ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
                    WriteError(new ErrorRecord(ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }

                if (_searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get the List of HotFixes installed on the Local Machine.
        /// </summary>
        protected override void BeginProcessing()
        {
            foreach (string computer in ComputerName)
            {
                bool              foundRecord = false;
                StringBuilder     QueryString = new StringBuilder();
                ConnectionOptions conOptions  = ComputerWMIHelper.GetConnectionOptions(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
                ManagementScope   scope       = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), conOptions);
                scope.Connect();
                if (Id != null)
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int i = 0; i <= Id.Length - 1; i++)
                    {
                        QueryString.Append("HotFixID= '");
                        QueryString.Append(Id[i].ToString().Replace("'", "\\'"));
                        QueryString.Append("'");
                        if (i < Id.Length - 1)
                        {
                            QueryString.Append(" Or ");
                        }
                    }

                    QueryString.Append(")");
                }
                else
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering");
                    foundRecord = true;
                }

                _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
                foreach (ManagementObject obj in _searchProcess.Get())
                {
                    if (Description != null)
                    {
                        if (!FilterMatch(obj))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        _inputContainsWildcard = true;
                    }

                    // try to translate the SID to a more friendly username
                    // just stick with the SID if anything goes wrong
                    string installed = (string)obj["InstalledBy"];
                    if (!String.IsNullOrEmpty(installed))
                    {
                        try
                        {
                            SecurityIdentifier secObj = new SecurityIdentifier(installed);
                            obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));;
                        }
                        catch (IdentityNotMappedException) // thrown by SecurityIdentifier.Translate
                        {
                        }
                        catch (SystemException) // thrown by SecurityIdentifier.constr
                        {
                        }
                        //catch (ArgumentException) // thrown (indirectly) by SecurityIdentifier.constr (on XP only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (PlatformNotSupportedException) // thrown (indirectly) by SecurityIdentifier.Translate (on Win95 only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (UnauthorizedAccessException) // thrown (indirectly) by SecurityIdentifier.Translate
                        //{ catch not needed - this is already caught as SystemException
                        //}
                    }

                    WriteObject(obj);
                    foundRecord = true;
                }

                if (!foundRecord && !_inputContainsWildcard)
                {
                    Exception Ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
                    WriteError(new ErrorRecord(Ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }

                if (_searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }//end of BeginProcessing method
 protected override void BeginProcessing()
 {
     if (!ComputerWMIHelper.SkipSystemRestoreOperationForARMPlatform(this))
     {
         try
         {
             ManagementScope managementScope = new ManagementScope("\\root\\default");
             managementScope.Connect();
             this.WMIClass       = new ManagementClass("SystemRestore");
             this.WMIClass.Scope = managementScope;
             if (base.ParameterSetName.Equals("LastStatus"))
             {
                 int num = Convert.ToInt32(this.WMIClass.InvokeMethod("GetLastRestoreStatus", null), CultureInfo.CurrentCulture);
                 if (!num.Equals(0))
                 {
                     if (!num.Equals(1))
                     {
                         if (num.Equals(2))
                         {
                             base.WriteObject(ComputerResources.RestoreInterrupted);
                         }
                     }
                     else
                     {
                         base.WriteObject(ComputerResources.RestoreSuceess);
                     }
                 }
                 else
                 {
                     base.WriteObject(ComputerResources.RestoreFailed);
                 }
             }
             Dictionary <int, string> nums = new Dictionary <int, string>();
             if (base.ParameterSetName.Equals("ID"))
             {
                 ObjectQuery objectQuery = new ObjectQuery();
                 if (this._restorepoint != null)
                 {
                     StringBuilder stringBuilder = new StringBuilder("select * from ");
                     stringBuilder.Append("SystemRestore");
                     stringBuilder.Append(" where  SequenceNumber = ");
                     for (int i = 0; i <= (int)this._restorepoint.Length - 1; i++)
                     {
                         stringBuilder.Append(this._restorepoint[i]);
                         if (i < (int)this._restorepoint.Length - 1)
                         {
                             stringBuilder.Append(" OR SequenceNumber = ");
                         }
                         if (!nums.ContainsKey(this._restorepoint[i]))
                         {
                             nums.Add(this._restorepoint[i], "true");
                         }
                     }
                     objectQuery.QueryString = stringBuilder.ToString();
                 }
                 else
                 {
                     objectQuery.QueryString = "select * from SystemRestore";
                 }
                 ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery);
                 foreach (ManagementObject managementObject in managementObjectSearcher.Get())
                 {
                     base.WriteObject(managementObject);
                     if (this._restorepoint == null)
                     {
                         continue;
                     }
                     int num1 = Convert.ToInt32(managementObject.Properties["SequenceNumber"].Value, CultureInfo.CurrentCulture);
                     if (!nums.ContainsKey(num1))
                     {
                         continue;
                     }
                     nums.Remove(num1);
                 }
                 if (nums != null && nums.Count > 0)
                 {
                     foreach (int key in nums.Keys)
                     {
                         string            str = StringUtil.Format(ComputerResources.NoResorePoint, key);
                         ArgumentException argumentException = new ArgumentException(str);
                         ErrorRecord       errorRecord       = new ErrorRecord(argumentException, "NoResorePoint", ErrorCategory.InvalidArgument, null);
                         base.WriteError(errorRecord);
                     }
                 }
             }
         }
         catch (ManagementException managementException1)
         {
             ManagementException managementException = managementException1;
             if (managementException.ErrorCode.Equals(ManagementStatus.NotFound) || managementException.ErrorCode.Equals(ManagementStatus.InvalidClass))
             {
                 Exception exception = new ArgumentException(StringUtil.Format(ComputerResources.NotSupported, new object[0]));
                 base.WriteError(new ErrorRecord(exception, "GetComputerRestorePointNotSupported", ErrorCategory.InvalidOperation, null));
             }
             else
             {
                 ErrorRecord errorRecord1 = new ErrorRecord(managementException, "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                 base.WriteError(errorRecord1);
             }
         }
         catch (COMException cOMException1)
         {
             COMException cOMException = cOMException1;
             if (!string.IsNullOrEmpty(cOMException.Message))
             {
                 ErrorRecord errorRecord2 = new ErrorRecord(cOMException, "COMException", ErrorCategory.InvalidOperation, null);
                 base.WriteError(errorRecord2);
             }
             else
             {
                 Exception argumentException1 = new ArgumentException(StringUtil.Format(ComputerResources.SystemRestoreServiceDisabled, new object[0]));
                 base.WriteError(new ErrorRecord(argumentException1, "ServiceDisabled", ErrorCategory.InvalidOperation, null));
             }
         }
         return;
     }
     else
     {
         return;
     }
 }
Beispiel #5
0
        protected override void ProcessRecord()
        {
            string            hostName;
            ConnectionOptions connection = ComputerWMIHelper.GetConnection(this.Authentication, this.Impersonation, this.Credential);

            object[] objArray = new object[2];
            objArray[0] = 1;
            objArray[1] = 0;
            object[] objArray1 = objArray;
            if (this._force.IsPresent)
            {
                objArray1[0] = 5;
            }
            if (!this._asjob.IsPresent)
            {
                string   empty     = string.Empty;
                string[] strArrays = this._computername;
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string str = strArrays[i];
                    if (str.Equals("localhost", StringComparison.CurrentCultureIgnoreCase) || str.Equals(".", StringComparison.OrdinalIgnoreCase))
                    {
                        hostName = Dns.GetHostName();
                        empty    = "localhost";
                    }
                    else
                    {
                        hostName = str;
                    }
                    if (base.ShouldProcess(StringUtil.Format(ComputerResources.DoubleComputerName, empty, hostName)))
                    {
                        try
                        {
                            ManagementScope    managementScope   = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection);
                            EnumerationOptions enumerationOption = new EnumerationOptions();
                            enumerationOption.UseAmendedQualifiers = true;
                            enumerationOption.DirectRead           = true;
                            ObjectQuery objectQuery = new ObjectQuery("select * from Win32_OperatingSystem");
                            this.searcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption);
                            foreach (ManagementObject managementObject in this.searcher.Get())
                            {
                                object obj = managementObject.InvokeMethod("Win32shutdown", objArray1);
                                int    num = Convert.ToInt32(obj.ToString(), CultureInfo.CurrentCulture);
                                if (num == 0)
                                {
                                    continue;
                                }
                                ComputerWMIHelper.WriteNonTerminatingError(num, this, hostName);
                            }
                        }
                        catch (ManagementException managementException1)
                        {
                            ManagementException managementException = managementException1;
                            ErrorRecord         errorRecord         = new ErrorRecord(managementException, "StopComputerException", ErrorCategory.InvalidOperation, hostName);
                            base.WriteError(errorRecord);
                        }
                        catch (COMException cOMException1)
                        {
                            COMException cOMException = cOMException1;
                            ErrorRecord  errorRecord1 = new ErrorRecord(cOMException, "StopComputerException", ErrorCategory.InvalidOperation, hostName);
                            base.WriteError(errorRecord1);
                        }
                    }
                }
                return;
            }
            else
            {
                string machineNames = ComputerWMIHelper.GetMachineNames(this.ComputerName);
                if (base.ShouldProcess(machineNames))
                {
                    InvokeWmiMethod invokeWmiMethod = new InvokeWmiMethod();
                    invokeWmiMethod.Path                = "Win32_OperatingSystem=@";
                    invokeWmiMethod.ComputerName        = this._computername;
                    invokeWmiMethod.Authentication      = this._authentication;
                    invokeWmiMethod.Impersonation       = this._impersonation;
                    invokeWmiMethod.Credential          = this._credential;
                    invokeWmiMethod.ThrottleLimit       = this._throttlelimit;
                    invokeWmiMethod.Name                = "Win32Shutdown";
                    invokeWmiMethod.EnableAllPrivileges = SwitchParameter.Present;
                    invokeWmiMethod.ArgumentList        = objArray1;
                    PSWmiJob pSWmiJob = new PSWmiJob(invokeWmiMethod, this._computername, this._throttlelimit, Job.GetCommandTextFromInvocationInfo(base.MyInvocation));
                    base.JobRepository.Add(pSWmiJob);
                    base.WriteObject(pSWmiJob);
                    return;
                }
                else
                {
                    return;
                }
            }
        }
 protected override void BeginProcessing()
 {
     if (!ComputerWMIHelper.SkipSystemRestoreOperationForARMPlatform(this))
     {
         CheckpointComputerCommand.exceptionfromnewthread = null;
         if (Environment.OSVersion.Version.Major >= 6 && this.intRestorePoint == 13)
         {
             ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(StringUtil.Format(ComputerResources.NotSupported, new object[0])), null, ErrorCategory.InvalidOperation, null);
             base.ThrowTerminatingError(errorRecord);
         }
         if (this.CanCreateNewRestorePoint(DateTime.Now))
         {
             this.startUtcTime   = DateTime.UtcNow;
             this.startLocalTime = DateTime.Now;
             ThreadStart threadStart = new ThreadStart(this.CreateRestorePoint);
             Thread      thread      = new Thread(threadStart);
             thread.Start();
             this.WriteProgress();
             if (CheckpointComputerCommand.exceptionfromnewthread != null)
             {
                 if (CheckpointComputerCommand.exceptionfromnewthread as COMException == null)
                 {
                     if (CheckpointComputerCommand.exceptionfromnewthread as ManagementException == null)
                     {
                         throw CheckpointComputerCommand.exceptionfromnewthread;
                     }
                     else
                     {
                         if (((ManagementException)CheckpointComputerCommand.exceptionfromnewthread).ErrorCode.Equals(ManagementStatus.NotFound) || ((ManagementException)CheckpointComputerCommand.exceptionfromnewthread).ErrorCode.Equals(ManagementStatus.InvalidClass))
                         {
                             Exception argumentException = new ArgumentException(StringUtil.Format(ComputerResources.NotSupported, new object[0]));
                             base.WriteError(new ErrorRecord(argumentException, "CheckpointComputerNotSupported", ErrorCategory.InvalidOperation, null));
                             return;
                         }
                         else
                         {
                             ErrorRecord errorRecord1 = new ErrorRecord(CheckpointComputerCommand.exceptionfromnewthread, "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                             base.WriteError(errorRecord1);
                             return;
                         }
                     }
                 }
                 else
                 {
                     if (!string.IsNullOrEmpty(CheckpointComputerCommand.exceptionfromnewthread.Message))
                     {
                         ErrorRecord errorRecord2 = new ErrorRecord(CheckpointComputerCommand.exceptionfromnewthread, "COMException", ErrorCategory.InvalidOperation, null);
                         base.WriteError(errorRecord2);
                         return;
                     }
                     else
                     {
                         Exception exception = new ArgumentException(StringUtil.Format(ComputerResources.SystemRestoreServiceDisabled, new object[0]));
                         base.WriteError(new ErrorRecord(exception, "ServiceDisabled", ErrorCategory.InvalidOperation, null));
                         return;
                     }
                 }
             }
             else
             {
                 if (!this.ret.Equals(0x422))
                 {
                     if (this.ret.Equals(0) || this.ret.Equals(0x422))
                     {
                         return;
                     }
                     else
                     {
                         Exception argumentException1 = new ArgumentException(StringUtil.Format(ComputerResources.RestorePointNotCreated, new object[0]));
                         base.WriteError(new ErrorRecord(argumentException1, "CheckpointComputerPointNotCreated", ErrorCategory.InvalidOperation, null));
                         return;
                     }
                 }
                 else
                 {
                     Exception exception1 = new ArgumentException(StringUtil.Format(ComputerResources.ServiceDisabled, new object[0]));
                     base.WriteError(new ErrorRecord(exception1, "CheckpointComputerServiceDisabled", ErrorCategory.InvalidOperation, null));
                     return;
                 }
             }
         }
         else
         {
             base.WriteWarning(ComputerResources.CannotCreateRestorePointWarning);
             return;
         }
     }
     else
     {
         return;
     }
 }
Beispiel #7
0
        internal static void ResetMachineAccountPassword(string domain, string localMachineName, string server, PSCredential credential, PSCmdlet cmdlet)
        {
            SAMAPI.LSA_UNICODE_STRING structure;
            string            userName;
            string            stringFromSecureString;
            string            cannotFindMachineAccountFromServer;
            DirectoryEntry    directoryEntry    = null;
            DirectoryEntry    directoryEntry1   = null;
            DirectorySearcher directorySearcher = null;
            string            randomPassword    = null;
            string            str  = server;
            string            str1 = str;

            if (str == null)
            {
                str1 = domain;
            }
            string str2 = str1;

            try
            {
                try
                {
                    if (credential != null)
                    {
                        userName = credential.UserName;
                    }
                    else
                    {
                        userName = null;
                    }
                    string str3 = userName;
                    if (credential != null)
                    {
                        stringFromSecureString = Utils.GetStringFromSecureString(credential.Password);
                    }
                    else
                    {
                        stringFromSecureString = null;
                    }
                    string str4 = stringFromSecureString;
                    directoryEntry    = new DirectoryEntry(string.Concat("LDAP://", str2), str3, str4, AuthenticationTypes.Secure);
                    directorySearcher = new DirectorySearcher(directoryEntry);
                    string[] strArrays = new string[5];
                    strArrays[0]             = "(&(objectClass=computer)(|(cn=";
                    strArrays[1]             = localMachineName;
                    strArrays[2]             = ")(dn=";
                    strArrays[3]             = localMachineName;
                    strArrays[4]             = ")))";
                    directorySearcher.Filter = string.Concat(strArrays);
                    SearchResult searchResult = directorySearcher.FindOne();
                    if (searchResult != null)
                    {
                        directoryEntry1 = searchResult.GetDirectoryEntry();
                        randomPassword  = ComputerWMIHelper.GetRandomPassword(120);
                        object[] objArray = new object[1];
                        objArray[0] = randomPassword;
                        directoryEntry1.Invoke("SetPassword", objArray);
                        directoryEntry1.Properties["LockOutTime"].Value = 0;
                    }
                    else
                    {
                        if (server != null)
                        {
                            cannotFindMachineAccountFromServer = ComputerResources.CannotFindMachineAccountFromServer;
                        }
                        else
                        {
                            cannotFindMachineAccountFromServer = ComputerResources.CannotFindMachineAccountFromDomain;
                        }
                        string      str5        = cannotFindMachineAccountFromServer;
                        string      str6        = StringUtil.Format(str5, str2);
                        ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str6), "CannotFindMachineAccount", ErrorCategory.OperationStopped, localMachineName);
                        cmdlet.ThrowTerminatingError(errorRecord);
                    }
                }
#if !MONO
                catch (DirectoryServicesCOMException directoryServicesCOMException1)
                {
                    DirectoryServicesCOMException directoryServicesCOMException = directoryServicesCOMException1;
                    string      str7         = StringUtil.Format(ComputerResources.FailToResetPasswordOnDomain, directoryServicesCOMException.Message);
                    ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str7), "FailToResetPasswordOnDomain", ErrorCategory.OperationStopped, localMachineName);
                    cmdlet.ThrowTerminatingError(errorRecord1);
                }
#endif
                catch (TargetInvocationException targetInvocationException1)
                {
                    TargetInvocationException targetInvocationException = targetInvocationException1;
                    string      str8         = StringUtil.Format(ComputerResources.FailToResetPasswordOnDomain, targetInvocationException.InnerException.Message);
                    ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(str8), "FailToResetPasswordOnDomain", ErrorCategory.OperationStopped, localMachineName);
                    cmdlet.ThrowTerminatingError(errorRecord2);
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    string       str9         = StringUtil.Format(ComputerResources.FailToResetPasswordOnDomain, cOMException.Message);
                    ErrorRecord  errorRecord3 = new ErrorRecord(new InvalidOperationException(str9), "FailToResetPasswordOnDomain", ErrorCategory.OperationStopped, localMachineName);
                    cmdlet.ThrowTerminatingError(errorRecord3);
                }
            }
            finally
            {
                if (directoryEntry != null)
                {
                    directoryEntry.Close();
                    directoryEntry.Dispose();
                }
                if (directorySearcher != null)
                {
                    directorySearcher.Dispose();
                }
                if (directoryEntry1 != null)
                {
                    directoryEntry1.Close();
                    directoryEntry1.Dispose();
                }
            }
            SAMAPI.LSA_OBJECT_ATTRIBUTES zero = new SAMAPI.LSA_OBJECT_ATTRIBUTES();
            zero.RootDirectory            = IntPtr.Zero;
            zero.ObjectName               = IntPtr.Zero;
            zero.Attributes               = 0;
            zero.SecurityDescriptor       = IntPtr.Zero;
            zero.SecurityQualityOfService = IntPtr.Zero;
            zero.Length = Marshal.SizeOf(typeof(SAMAPI.LSA_OBJECT_ATTRIBUTES));
            IntPtr intPtr  = IntPtr.Zero;
            IntPtr zero1   = IntPtr.Zero;
            IntPtr intPtr1 = IntPtr.Zero;
            SAMAPI.LSA_UNICODE_STRING lSAUNICODESTRING = new SAMAPI.LSA_UNICODE_STRING();
            lSAUNICODESTRING.Buffer = IntPtr.Zero;
            SAMAPI.LSA_UNICODE_STRING lSAUNICODESTRING1 = lSAUNICODESTRING;
            SAMAPI.LSA_UNICODE_STRING zero2             = new SAMAPI.LSA_UNICODE_STRING();
            zero2.Buffer = IntPtr.Zero;
            SAMAPI.LSA_UNICODE_STRING lSAUNICODESTRING2 = zero2;
            SAMAPI.LSA_UNICODE_STRING zero3             = new SAMAPI.LSA_UNICODE_STRING();
            zero3.Buffer        = IntPtr.Zero;
            zero3.Length        = 0;
            zero3.MaximumLength = 0;
            try
            {
                uint num = SAMAPI.LsaOpenPolicy(ref zero3, ref zero, 0xf0fff, out intPtr);
                if (num == -1073741790)
                {
                    string      needAdminPrivilegeToResetPassword = ComputerResources.NeedAdminPrivilegeToResetPassword;
                    ErrorRecord errorRecord4 = new ErrorRecord(new InvalidOperationException(needAdminPrivilegeToResetPassword), "UnauthorizedAccessException", ErrorCategory.InvalidOperation, localMachineName);
                    cmdlet.ThrowTerminatingError(errorRecord4);
                }
                if (num != 0)
                {
                    ResetComputerMachinePasswordCommand.ThrowOutLsaError(num, cmdlet);
                }
                SAMAPI.InitLsaString("$MACHINE.ACC", ref lSAUNICODESTRING1);
                SAMAPI.InitLsaString(randomPassword, ref lSAUNICODESTRING2);
                bool flag = false;
                num = SAMAPI.LsaOpenSecret(intPtr, ref lSAUNICODESTRING1, 3, out zero1);
                if (num == -1073741772)
                {
                    num  = SAMAPI.LsaCreateSecret(intPtr, ref lSAUNICODESTRING1, 1, out zero1);
                    flag = true;
                }
                if (num != 0)
                {
                    ResetComputerMachinePasswordCommand.ThrowOutLsaError(num, cmdlet);
                }
                if (!flag)
                {
                    num = SAMAPI.LsaQuerySecret(zero1, out intPtr1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                    if (num != 0)
                    {
                        ResetComputerMachinePasswordCommand.ThrowOutLsaError(num, cmdlet);
                    }
                    structure = (SAMAPI.LSA_UNICODE_STRING)Marshal.PtrToStructure(intPtr1, typeof(SAMAPI.LSA_UNICODE_STRING));
                }
                else
                {
                    structure = lSAUNICODESTRING2;
                }
                num = SAMAPI.LsaSetSecret(zero1, ref lSAUNICODESTRING2, ref structure);
                if (num != 0)
                {
                    ResetComputerMachinePasswordCommand.ThrowOutLsaError(num, cmdlet);
                }
            }
            finally
            {
                if (intPtr1 != IntPtr.Zero)
                {
                    SAMAPI.LsaFreeMemory(intPtr1);
                }
                if (intPtr != IntPtr.Zero)
                {
                    SAMAPI.LsaClose(intPtr);
                }
                if (zero1 != IntPtr.Zero)
                {
                    SAMAPI.LsaClose(zero1);
                }
                SAMAPI.FreeLsaString(ref lSAUNICODESTRING1);
                SAMAPI.FreeLsaString(ref lSAUNICODESTRING2);
            }
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
 protected override void BeginProcessing()
 {
     if (!ComputerWMIHelper.SkipSystemRestoreOperationForARMPlatform(this))
     {
         try
         {
             ConnectionOptions connection     = ComputerWMIHelper.GetConnection(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, null);
             ManagementPath    managementPath = new ManagementPath();
             managementPath.Path = "\\root\\default";
             ManagementScope managementScope = new ManagementScope(managementPath, connection);
             managementScope.Connect();
             this.WMIClass       = new ManagementClass("SystemRestore");
             this.WMIClass.Scope = managementScope;
             ObjectQuery objectQuery = new ObjectQuery(string.Concat("select * from SystemRestore where SequenceNumber = ", this._restorepoint));
             ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery);
             if (managementObjectSearcher.Get().Count != 0)
             {
                 string machineName = Environment.MachineName;
                 if (base.ShouldProcess(machineName))
                 {
                     object[] objArray = new object[1];
                     objArray[0] = this._restorepoint;
                     object[] objArray1 = objArray;
                     this.WMIClass.InvokeMethod("Restore", objArray1);
                     managementPath.Path  = "\\root\\cimv2";
                     managementScope.Path = managementPath;
                     ManagementClass managementClass = new ManagementClass("Win32_OperatingSystem");
                     managementClass.Scope = managementScope;
                     ObjectQuery objectQuery1 = new ObjectQuery("Select * from Win32_OperatingSystem");
                     ManagementObjectSearcher managementObjectSearcher1 = new ManagementObjectSearcher(managementScope, objectQuery1);
                     foreach (ManagementObject managementObject in managementObjectSearcher1.Get())
                     {
                         string[] strArrays = new string[1];
                         strArrays[0] = "";
                         string[] strArrays1 = strArrays;
                         managementObject.InvokeMethod("Reboot", strArrays1);
                     }
                 }
             }
             else
             {
                 string            str = StringUtil.Format(ComputerResources.InvalidRestorePoint, this._restorepoint);
                 ArgumentException argumentException = new ArgumentException(str);
                 ErrorRecord       errorRecord       = new ErrorRecord(argumentException, "InvalidRestorePoint", ErrorCategory.InvalidArgument, null);
                 base.WriteError(errorRecord);
             }
         }
         catch (ManagementException managementException1)
         {
             ManagementException managementException = managementException1;
             if (managementException.ErrorCode.ToString().Equals("NotFound") || managementException.ErrorCode.ToString().Equals("InvalidClass"))
             {
                 Exception exception = new ArgumentException(StringUtil.Format(ComputerResources.NotSupported, new object[0]));
                 base.WriteError(new ErrorRecord(exception, "RestoreComputerNotSupported", ErrorCategory.InvalidOperation, null));
             }
             else
             {
                 ErrorRecord errorRecord1 = new ErrorRecord(managementException, "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                 base.WriteError(errorRecord1);
             }
         }
         catch (COMException cOMException1)
         {
             COMException cOMException = cOMException1;
             if (!string.IsNullOrEmpty(cOMException.Message))
             {
                 ErrorRecord errorRecord2 = new ErrorRecord(cOMException, "COMException", ErrorCategory.InvalidOperation, null);
                 base.WriteError(errorRecord2);
             }
             else
             {
                 Exception argumentException1 = new ArgumentException(StringUtil.Format(ComputerResources.SystemRestoreServiceDisabled, new object[0]));
                 base.WriteError(new ErrorRecord(argumentException1, "ServiceDisabled", ErrorCategory.InvalidOperation, null));
             }
         }
         return;
     }
     else
     {
         return;
     }
 }
        protected override void ProcessRecord()
        {
            ConnectionOptions connection = ComputerWMIHelper.GetConnection(this.Authentication, this.Impersonation, this.Credential);

            if (!this.asjob)
            {
                int      num       = 0;
                string[] strArrays = this.source;
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string str = strArrays[i];
                    try
                    {
                        num++;
                        string          str1            = this.QueryString(this.destination, true, true);
                        ObjectQuery     objectQuery     = new ObjectQuery(str1);
                        ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection);
                        managementScope.Options.EnablePrivileges = true;
                        managementScope.Connect();
                        EnumerationOptions enumerationOption = new EnumerationOptions();
                        enumerationOption.UseAmendedQualifiers = true;
                        enumerationOption.DirectRead           = true;
                        this.searcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption);
                        for (int j = 0; j <= this.count - 1; j++)
                        {
                            ManagementObjectCollection managementObjectCollections = this.searcher.Get();
                            int num1 = 0;
                            foreach (ManagementBaseObject managementBaseObject in managementObjectCollections)
                            {
                                num1++;
                                this.ProcessPingStatus(managementBaseObject);
                                if (num1 >= managementObjectCollections.Count && j >= this.count - 1 && num >= (int)this.Source.Length)
                                {
                                    continue;
                                }
                                Thread.Sleep(this.delay * 0x3e8);
                            }
                        }
                    }
                    catch (ManagementException managementException1)
                    {
                        ManagementException managementException = managementException1;
                        ErrorRecord         errorRecord         = new ErrorRecord(managementException, "TestConnectionException", ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord);
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        ErrorRecord  errorRecord1 = new ErrorRecord(cOMException, "TestConnectionException", ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord1);
                    }
                }
            }
            else
            {
                string str2 = this.QueryString(this.destination, true, false);
                GetWmiObjectCommand getWmiObjectCommand = new GetWmiObjectCommand();
                getWmiObjectCommand.Filter         = str2.ToString();
                getWmiObjectCommand.Class          = "Win32_PingStatus";
                getWmiObjectCommand.ComputerName   = this.source;
                getWmiObjectCommand.Authentication = this.Authentication;
                getWmiObjectCommand.Impersonation  = this.Impersonation;
                getWmiObjectCommand.ThrottleLimit  = this.throttlelimit;
                PSWmiJob pSWmiJob = new PSWmiJob(getWmiObjectCommand, this.source, this.throttlelimit, base.MyInvocation.MyCommand.Name, this.count);
                base.JobRepository.Add(pSWmiJob);
                base.WriteObject(pSWmiJob);
            }
            if (this.quiet)
            {
                string[] strArrays1 = this.destination;
                for (int k = 0; k < (int)strArrays1.Length; k++)
                {
                    string str3 = strArrays1[k];
                    bool   flag = false;
                    this.quietResults.TryGetValue(str3, out flag);
                    base.WriteObject(flag);
                }
            }
        }
Beispiel #11
0
        private void DoAddComputerAction(string computer, string newName, bool isLocalhost, ConnectionOptions options, EnumerationOptions enumOptions, ObjectQuery computerSystemQuery)
        {
            string str;
            string userName;
            string stringFromSecureString;
            string userName1;
            string stringFromSecureString1;
            int    num  = 0;
            bool   flag = false;

            if (isLocalhost)
            {
                str = this._shortLocalMachineName;
            }
            else
            {
                str = computer;
            }
            string str1 = str;

            if (base.ParameterSetName != "Domain")
            {
                string str2 = StringUtil.Format(ComputerResources.AddComputerActionWorkgroup, this._workgroupName);
                if (!base.ShouldProcess(str1, str2))
                {
                    return;
                }
            }
            else
            {
                string str3 = StringUtil.Format(ComputerResources.AddComputerActionDomain, this._domainName);
                if (!base.ShouldProcess(str1, str3))
                {
                    return;
                }
            }
            if (newName != null && newName.Length > 15)
            {
                string str4 = newName.Substring(0, 15);
                string str5 = StringUtil.Format(ComputerResources.TruncateNetBIOSName, str4);
                string truncateNetBIOSNameCaption = ComputerResources.TruncateNetBIOSNameCaption;
                if (!this.Force && !base.ShouldContinue(str5, truncateNetBIOSNameCaption))
                {
                    return;
                }
            }
            if (this.LocalCredential != null)
            {
                //options.SecurePassword = this.LocalCredential.Password;
                options.Username = ComputerWMIHelper.GetLocalAdminUserName(str1, this.LocalCredential);
            }
            if (isLocalhost)
            {
                options.Username = null;
                //options.SecurePassword = null;
            }
            ManagementObjectSearcher managementObjectSearcher = null;
            ManagementScope          managementScope          = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, "\\root\\cimv2"), options);

            using (managementObjectSearcher)
            {
                try
                {
                    managementObjectSearcher = new ManagementObjectSearcher(managementScope, computerSystemQuery, enumOptions);
                    foreach (ManagementObject managementObject in managementObjectSearcher.Get())
                    {
                        string item = (string)managementObject["DNSHostName"];
                        if (newName == null && item.Length > 15)
                        {
                            string str6 = item.Substring(0, 15);
                            string str7 = StringUtil.Format(ComputerResources.TruncateNetBIOSName, str6);
                            string truncateNetBIOSNameCaption1 = ComputerResources.TruncateNetBIOSNameCaption;
                            if (!this.Force && !base.ShouldContinue(str7, truncateNetBIOSNameCaption1))
                            {
                                continue;
                            }
                        }
                        if (newName == null || !item.Equals(newName, StringComparison.OrdinalIgnoreCase))
                        {
                            if (base.ParameterSetName != "Domain")
                            {
                                if (!(bool)managementObject["PartOfDomain"])
                                {
                                    string str8 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                                    if (!str8.Equals(this._workgroupName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        num = this.JoinWorkgroup(managementObject, str1, null);
                                        if (num == 0 && newName != null)
                                        {
                                            num = this.RenameComputer(managementObject, str1, newName);
                                        }
                                        flag = num == 0;
                                    }
                                    else
                                    {
                                        object[] objArray = new object[2];
                                        objArray[0] = str1;
                                        objArray[1] = this._workgroupName;
                                        this.WriteErrorHelper(ComputerResources.AddComputerToSameWorkgroup, "AddComputerToSameWorkgroup", str1, ErrorCategory.InvalidOperation, false, objArray);
                                        continue;
                                    }
                                }
                                else
                                {
                                    string removeComputerConfirm = ComputerResources.RemoveComputerConfirm;
                                    if (!this.Force && !base.ShouldContinue(removeComputerConfirm, null))
                                    {
                                        continue;
                                    }
                                    string str9 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                                    if (this.Credential != null)
                                    {
                                        userName = this.Credential.UserName;
                                    }
                                    else
                                    {
                                        userName = null;
                                    }
                                    string str10 = userName;
                                    if (this.Credential != null)
                                    {
                                        stringFromSecureString = Utils.GetStringFromSecureString(this.Credential.Password);
                                    }
                                    else
                                    {
                                        stringFromSecureString = null;
                                    }
                                    string str11 = stringFromSecureString;
                                    num = this.UnjoinDomain(managementObject, str1, str9, str10, str11);
                                    if (num == 0)
                                    {
                                        num = this.JoinWorkgroup(managementObject, str1, str9);
                                        if (num == 0 && newName != null)
                                        {
                                            num = this.RenameComputer(managementObject, str1, newName);
                                        }
                                    }
                                    flag = num == 0;
                                }
                            }
                            else
                            {
                                if (!(bool)managementObject["PartOfDomain"])
                                {
                                    string str12 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                                    num = this.JoinDomain(managementObject, str1, null, str12);
                                    if (num == 0 && newName != null)
                                    {
                                        num = this.RenameComputer(managementObject, str1, newName);
                                    }
                                    flag = num == 0;
                                }
                                else
                                {
                                    string str13 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                                    string str14 = "";
                                    if (str13.Contains("."))
                                    {
                                        int num1 = str13.IndexOf(".", StringComparison.OrdinalIgnoreCase);
                                        str14 = str13.Substring(0, num1);
                                    }
                                    if (str13.Equals(this._domainName, StringComparison.OrdinalIgnoreCase) || str14.Equals(this._domainName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        object[] objArray1 = new object[2];
                                        objArray1[0] = str1;
                                        objArray1[1] = this._domainName;
                                        this.WriteErrorHelper(ComputerResources.AddComputerToSameDomain, "AddComputerToSameDomain", str1, ErrorCategory.InvalidOperation, false, objArray1);
                                        continue;
                                    }
                                    else
                                    {
                                        PSCredential unjoinDomainCredential = this.UnjoinDomainCredential;
                                        PSCredential credential             = unjoinDomainCredential;
                                        if (unjoinDomainCredential == null)
                                        {
                                            credential = this.Credential;
                                        }
                                        PSCredential pSCredential = credential;
                                        if (pSCredential != null)
                                        {
                                            userName1 = pSCredential.UserName;
                                        }
                                        else
                                        {
                                            userName1 = null;
                                        }
                                        string str15 = userName1;
                                        if (pSCredential != null)
                                        {
                                            stringFromSecureString1 = Utils.GetStringFromSecureString(pSCredential.Password);
                                        }
                                        else
                                        {
                                            stringFromSecureString1 = null;
                                        }
                                        string str16 = stringFromSecureString1;
                                        num = this.UnjoinDomain(managementObject, str1, str13, str15, str16);
                                        if (num == 0)
                                        {
                                            num = this.JoinDomain(managementObject, str1, str13, null);
                                            if (num == 0 && newName != null)
                                            {
                                                num = this.RenameComputer(managementObject, str1, newName);
                                            }
                                        }
                                        flag = num == 0;
                                    }
                                }
                            }
                            if (!this._passThru)
                            {
                                continue;
                            }
                            base.WriteObject(ComputerWMIHelper.GetComputerStatusObject(num, str1));
                        }
                        else
                        {
                            object[] objArray2 = new object[2];
                            objArray2[0] = str1;
                            objArray2[1] = newName;
                            this.WriteErrorHelper(ComputerResources.NewNameIsOldName, "NewNameIsOldName", newName, ErrorCategory.InvalidArgument, false, objArray2);
                        }
                    }
                    if (flag && this._restart)
                    {
                        object[] objArray3 = new object[2];
                        objArray3[0] = 6;
                        objArray3[1] = 0;
                        object[] objArray4 = objArray3;
                        RestartComputerCommand.RestartOneComputerUsingDcom(this, isLocalhost, str1, objArray4, options);
                    }
                    if (flag && !this._restart)
                    {
                        base.WriteWarning(StringUtil.Format(ComputerResources.RestartNeeded, null, str1));
                    }
                }
                catch (ManagementException managementException1)
                {
                    ManagementException managementException = managementException1;
                    object[]            message             = new object[2];
                    message[0] = str1;
                    message[1] = managementException.Message;
                    this.WriteErrorHelper(ComputerResources.FailToConnectToComputer, "AddComputerException", str1, ErrorCategory.OperationStopped, false, message);
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    object[]     message1     = new object[2];
                    message1[0] = str1;
                    message1[1] = cOMException.Message;
                    this.WriteErrorHelper(ComputerResources.FailToConnectToComputer, "AddComputerException", str1, ErrorCategory.OperationStopped, false, message1);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    object[] message2 = new object[2];
                    message2[0] = str1;
                    message2[1] = unauthorizedAccessException.Message;
                    this.WriteErrorHelper(ComputerResources.FailToConnectToComputer, "AddComputerException", str1, ErrorCategory.OperationStopped, false, message2);
                }
            }
        }
Beispiel #12
0
        protected override void BeginProcessing()
        {
            bool flag = false;

            string[] strArrays = this._computername;
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string            str             = strArrays[i];
                StringBuilder     stringBuilder   = new StringBuilder();
                ConnectionOptions connection      = ComputerWMIHelper.GetConnection(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
                ManagementScope   managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection);
                managementScope.Connect();
                if (this._id == null)
                {
                    stringBuilder.Append("Select * from Win32_QuickFixEngineering");
                    flag = true;
                }
                else
                {
                    stringBuilder.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int j = 0; j <= (int)this._id.Length - 1; j++)
                    {
                        stringBuilder.Append("HotFixID= '");
                        stringBuilder.Append(this._id[j].ToString().Replace("'", "\\'"));
                        stringBuilder.Append("'");
                        if (j < (int)this._id.Length - 1)
                        {
                            stringBuilder.Append(" Or ");
                        }
                    }
                    stringBuilder.Append(")");
                }
                this.searchProcess = new ManagementObjectSearcher(managementScope, new ObjectQuery(stringBuilder.ToString()));
                foreach (ManagementObject managementObject in this.searchProcess.Get())
                {
                    if (this._description == null)
                    {
                        this.inputContainsWildcard = true;
                    }
                    else
                    {
                        if (!this.FilterMatch(managementObject))
                        {
                            continue;
                        }
                    }
                    string item = (string)managementObject["InstalledBy"];
                    if (!string.IsNullOrEmpty(item))
                    {
                        try
                        {
                            SecurityIdentifier securityIdentifier = new SecurityIdentifier(item);
                            managementObject["InstalledBy"] = securityIdentifier.Translate(typeof(NTAccount));
                        }
                        catch (IdentityNotMappedException identityNotMappedException)
                        {
                        }
                        catch (SystemException systemException1)
                        {
                            SystemException systemException = systemException1;
                            CommandsCommon.CheckForSevereException(this, systemException);
                        }
                    }
                    base.WriteObject(managementObject);
                    flag = true;
                }
                if (!flag && !this.inputContainsWildcard)
                {
                    Exception argumentException = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, str));
                    base.WriteError(new ErrorRecord(argumentException, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }
                if (this.searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }
        private void ConnectInvokeWmi()
        {
            ManagementObject managementObject;
            object           obj;
            string           str;
            InvokeWmiMethod  invokeWmiMethod = (InvokeWmiMethod)this.wmiObject;

            this.state = WmiState.Running;
            this.RaiseWmiOperationState(null, WmiState.Running);
            if (invokeWmiMethod.InputObject == null)
            {
                ConnectionOptions connectionOption = invokeWmiMethod.GetConnectionOption();
                ManagementPath    managementPath   = null;
                if (invokeWmiMethod.Path != null)
                {
                    managementPath = new ManagementPath(invokeWmiMethod.Path);
                    if (!string.IsNullOrEmpty(managementPath.NamespacePath))
                    {
                        if (invokeWmiMethod.namespaceSpecified)
                        {
                            InvalidOperationException invalidOperationException = new InvalidOperationException("NamespaceSpecifiedWithPath");
                            this.internalException = invalidOperationException;
                            this.state             = WmiState.Failed;
                            this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                            return;
                        }
                    }
                    else
                    {
                        managementPath.NamespacePath = invokeWmiMethod.Namespace;
                    }
                    if (!(managementPath.Server != ".") || !invokeWmiMethod.serverNameSpecified)
                    {
                        if (!(managementPath.Server == ".") || !invokeWmiMethod.serverNameSpecified)
                        {
                            this.computerName = managementPath.Server;
                        }
                    }
                    else
                    {
                        InvalidOperationException invalidOperationException1 = new InvalidOperationException("ComputerNameSpecifiedWithPath");
                        this.internalException = invalidOperationException1;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                        return;
                    }
                }
                bool flag            = false;
                bool enablePrivilege = false;
                Win32Native.TOKEN_PRIVILEGE tOKENPRIVILEGE = new Win32Native.TOKEN_PRIVILEGE();
                try
                {
                    try
                    {
                        enablePrivilege = this.NeedToEnablePrivilege(this.computerName, invokeWmiMethod.Name, ref flag);
                        if (!enablePrivilege || flag && ComputerWMIHelper.EnableTokenPrivilege("SeShutdownPrivilege", ref tOKENPRIVILEGE) || !flag && ComputerWMIHelper.EnableTokenPrivilege("SeRemoteShutdownPrivilege", ref tOKENPRIVILEGE))
                        {
                            if (invokeWmiMethod.Path == null)
                            {
                                ManagementScope managementScope = new ManagementScope(WMIHelper.GetScopeString(this.computerName, invokeWmiMethod.Namespace), connectionOption);
                                ManagementClass managementClass = new ManagementClass(invokeWmiMethod.Class);
                                managementObject       = managementClass;
                                managementObject.Scope = managementScope;
                            }
                            else
                            {
                                managementPath.Server = this.computerName;
                                if (!managementPath.IsClass)
                                {
                                    ManagementObject managementObject1 = new ManagementObject(managementPath);
                                    managementObject = managementObject1;
                                }
                                else
                                {
                                    ManagementClass managementClass1 = new ManagementClass(managementPath);
                                    managementObject = managementClass1;
                                }
                                ManagementScope managementScope1 = new ManagementScope(managementPath, connectionOption);
                                managementObject.Scope = managementScope1;
                            }
                            ManagementBaseObject methodParameters = managementObject.GetMethodParameters(invokeWmiMethod.Name);
                            if (invokeWmiMethod.ArgumentList != null)
                            {
                                int length = (int)invokeWmiMethod.ArgumentList.Length;
                                foreach (PropertyData property in methodParameters.Properties)
                                {
                                    if (length == 0)
                                    {
                                        break;
                                    }
                                    property.Value = invokeWmiMethod.ArgumentList[(int)invokeWmiMethod.ArgumentList.Length - length];
                                    length--;
                                }
                            }
                            if (!enablePrivilege)
                            {
                                managementObject.InvokeMethod(this.results, invokeWmiMethod.Name, methodParameters, null);
                            }
                            else
                            {
                                ManagementBaseObject managementBaseObject = managementObject.InvokeMethod(invokeWmiMethod.Name, methodParameters, null);
                                int num = Convert.ToInt32(managementBaseObject["ReturnValue"], CultureInfo.CurrentCulture);
                                if (num == 0)
                                {
                                    this.ShutdownComplete.SafeInvoke <EventArgs>(this, null);
                                }
                                else
                                {
                                    Win32Exception win32Exception = new Win32Exception(num);
                                    this.internalException = win32Exception;
                                    this.state             = WmiState.Failed;
                                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                }
                            }
                        }
                        else
                        {
                            string privilegeNotEnabled = ComputerResources.PrivilegeNotEnabled;
                            string str1 = this.computerName;
                            if (flag)
                            {
                                obj = "SeShutdownPrivilege";
                            }
                            else
                            {
                                obj = "SeRemoteShutdownPrivilege";
                            }
                            string str2 = StringUtil.Format(privilegeNotEnabled, str1, obj);
                            InvalidOperationException invalidOperationException2 = new InvalidOperationException(str2);
                            this.internalException = invalidOperationException2;
                            this.state             = WmiState.Failed;
                            this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                            return;
                        }
                    }
                    catch (ManagementException managementException1)
                    {
                        ManagementException managementException = managementException1;
                        this.internalException = managementException;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        this.internalException = cOMException;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    catch (UnauthorizedAccessException unauthorizedAccessException1)
                    {
                        UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                        this.internalException = unauthorizedAccessException;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                }
                finally
                {
                    if (enablePrivilege)
                    {
                        if (flag)
                        {
                            str = "SeShutdownPrivilege";
                        }
                        else
                        {
                            str = "SeRemoteShutdownPrivilege";
                        }
                        ComputerWMIHelper.RestoreTokenPrivilege(str, ref tOKENPRIVILEGE);
                    }
                }
                return;
            }
            else
            {
                try
                {
                    ManagementBaseObject methodParameters1 = invokeWmiMethod.InputObject.GetMethodParameters(invokeWmiMethod.Name);
                    if (invokeWmiMethod.ArgumentList != null)
                    {
                        int length1 = (int)invokeWmiMethod.ArgumentList.Length;
                        foreach (PropertyData argumentList in methodParameters1.Properties)
                        {
                            if (length1 == 0)
                            {
                                break;
                            }
                            argumentList.Value = invokeWmiMethod.ArgumentList[(int)invokeWmiMethod.ArgumentList.Length - length1];
                            length1--;
                        }
                    }
                    invokeWmiMethod.InputObject.InvokeMethod(this.results, invokeWmiMethod.Name, methodParameters1, null);
                }
                catch (ManagementException managementException3)
                {
                    ManagementException managementException2 = managementException3;
                    this.internalException = managementException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (COMException cOMException3)
                {
                    COMException cOMException2 = cOMException3;
                    this.internalException = cOMException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException3)
                {
                    UnauthorizedAccessException unauthorizedAccessException2 = unauthorizedAccessException3;
                    this.internalException = unauthorizedAccessException2;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                return;
            }
        }
        private void DoRemoveComputerAction(string computer, bool isLocalhost, ConnectionOptions options, EnumerationOptions enumOptions, ObjectQuery computerSystemQuery)
        {
            string str;
            string userName;
            string stringFromSecureString;
            bool   flag = false;

            if (isLocalhost)
            {
                str = this._shortLocalMachineName;
            }
            else
            {
                str = computer;
            }
            string str1 = str;

            if (base.ShouldProcess(str1))
            {
                if (this.LocalCredential != null)
                {
                    //options.SecurePassword = this.LocalCredential.Password;
                    options.Username = ComputerWMIHelper.GetLocalAdminUserName(str1, this.LocalCredential);
                }
                if (isLocalhost)
                {
                    options.Username = null;
                    //options.SecurePassword = null;
                }
                ManagementObjectSearcher managementObjectSearcher = null;
                ManagementScope          managementScope          = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, "\\root\\cimv2"), options);
                using (managementObjectSearcher)
                {
                    try
                    {
                        managementObjectSearcher = new ManagementObjectSearcher(managementScope, computerSystemQuery, enumOptions);
                        foreach (ManagementObject managementObject in managementObjectSearcher.Get())
                        {
                            if ((bool)managementObject["PartOfDomain"])
                            {
                                string removeComputerConfirm = ComputerResources.RemoveComputerConfirm;
                                if (!this.Force && !base.ShouldContinue(removeComputerConfirm, null))
                                {
                                    continue;
                                }
                                string str2 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                                if (this.UnjoinDomainCredential != null)
                                {
                                    userName = this.UnjoinDomainCredential.UserName;
                                }
                                else
                                {
                                    userName = null;
                                }
                                string str3 = userName;
                                if (this.UnjoinDomainCredential != null)
                                {
                                    stringFromSecureString = Utils.GetStringFromSecureString(this.UnjoinDomainCredential.Password);
                                }
                                else
                                {
                                    stringFromSecureString = null;
                                }
                                string str4 = stringFromSecureString;
                                ManagementBaseObject methodParameters = managementObject.GetMethodParameters("UnjoinDomainOrWorkgroup");
                                methodParameters.SetPropertyValue("UserName", str3);
                                methodParameters.SetPropertyValue("Password", str4);
                                methodParameters.SetPropertyValue("FUnjoinOptions", 4);
                                ManagementBaseObject managementBaseObject = managementObject.InvokeMethod("UnjoinDomainOrWorkgroup", methodParameters, null);
                                int num = Convert.ToInt32(managementBaseObject["ReturnValue"], CultureInfo.CurrentCulture);
                                if ((num == 0x54b || num == 53) && this.Force)
                                {
                                    methodParameters.SetPropertyValue("FUnjoinOptions", 0);
                                    managementBaseObject = managementObject.InvokeMethod("UnjoinDomainOrWorkgroup", methodParameters, null);
                                    num = Convert.ToInt32(managementBaseObject["ReturnValue"], CultureInfo.CurrentCulture);
                                }
                                if (num == 0)
                                {
                                    flag = true;
                                    if (this._workGroup != null)
                                    {
                                        ManagementBaseObject methodParameters1 = managementObject.GetMethodParameters("JoinDomainOrWorkgroup");
                                        methodParameters1.SetPropertyValue("Name", this._workGroup);
                                        methodParameters1.SetPropertyValue("Password", null);
                                        methodParameters1.SetPropertyValue("UserName", null);
                                        methodParameters1.SetPropertyValue("FJoinOptions", 0);
                                        managementBaseObject = managementObject.InvokeMethod("JoinDomainOrWorkgroup", methodParameters1, null);
                                        num = Convert.ToInt32(managementBaseObject["ReturnValue"], CultureInfo.CurrentCulture);
                                        if (num != 0)
                                        {
                                            Win32Exception win32Exception = new Win32Exception(num);
                                            object[]       message        = new object[4];
                                            message[0] = str1;
                                            message[1] = str2;
                                            message[2] = this._workGroup;
                                            message[3] = win32Exception.Message;
                                            string      str5        = StringUtil.Format(ComputerResources.FailToSwitchFromDomainToWorkgroup, message);
                                            ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str5), "FailToJoinWorkGroup", ErrorCategory.OperationStopped, str1);
                                            base.WriteError(errorRecord);
                                        }
                                    }
                                }
                                else
                                {
                                    Win32Exception win32Exception1 = new Win32Exception(num);
                                    object[]       objArray        = new object[3];
                                    objArray[0] = str1;
                                    objArray[1] = str2;
                                    objArray[2] = win32Exception1.Message;
                                    string      str6         = StringUtil.Format(ComputerResources.FailToUnjoinDomain, objArray);
                                    ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str6), "FailToUnjoinDomain", ErrorCategory.OperationStopped, str1);
                                    base.WriteError(errorRecord1);
                                }
                                if (!this._passThru)
                                {
                                    continue;
                                }
                                base.WriteObject(ComputerWMIHelper.GetComputerStatusObject(num, str1));
                            }
                            else
                            {
                                string      str7         = StringUtil.Format(ComputerResources.ComputerNotInDomain, str1);
                                ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(str7), "ComputerNotInDomain", ErrorCategory.InvalidOperation, str1);
                                base.WriteError(errorRecord2);
                            }
                        }
                        if (flag && this._restart)
                        {
                            object[] objArray1 = new object[2];
                            objArray1[0] = 6;
                            objArray1[1] = 0;
                            object[] objArray2 = objArray1;
                            RestartComputerCommand.RestartOneComputerUsingDcom(this, isLocalhost, str1, objArray2, options);
                        }
                        if (flag && !this._restart)
                        {
                            base.WriteWarning(StringUtil.Format(ComputerResources.RestartNeeded, null, str1));
                        }
                    }
                    catch (ManagementException managementException1)
                    {
                        ManagementException managementException = managementException1;
                        string      str8         = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, managementException.Message);
                        ErrorRecord errorRecord3 = new ErrorRecord(new InvalidOperationException(str8), "RemoveComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord3);
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        string       str9         = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, cOMException.Message);
                        ErrorRecord  errorRecord4 = new ErrorRecord(new InvalidOperationException(str9), "RemoveComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord4);
                    }
                    catch (UnauthorizedAccessException unauthorizedAccessException1)
                    {
                        UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                        string      str10        = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, unauthorizedAccessException.Message);
                        ErrorRecord errorRecord5 = new ErrorRecord(new InvalidOperationException(str10), "RemoveComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord5);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
        private string ValidateComputerName()
        {
            IPAddress pAddress = null;
            string    str;
            object    obj;
            string    str1 = null;

            if (this._computerName.Equals(".", StringComparison.OrdinalIgnoreCase) || this._computerName.Equals("localhost", StringComparison.OrdinalIgnoreCase) || this._computerName.Equals(this._shortLocalMachineName, StringComparison.OrdinalIgnoreCase) || this._computerName.Equals(this._fullLocalMachineName, StringComparison.OrdinalIgnoreCase))
            {
                str1 = "localhost";
            }
            else
            {
                bool flag = false;
                try
                {
                    flag = IPAddress.TryParse(this._computerName, out pAddress);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    CommandProcessorBase.CheckForSevereException(exception);
                }
                try
                {
                    string hostName = Dns.GetHostEntry(this._computerName).HostName;
                    if (hostName.Equals(this._shortLocalMachineName, StringComparison.OrdinalIgnoreCase) || hostName.Equals(this._fullLocalMachineName, StringComparison.OrdinalIgnoreCase))
                    {
                        str1 = "localhost";
                    }
                    else
                    {
                        str1 = this._computerName;
                    }
                    goto Label0;
                }
                catch (Exception exception3)
                {
                    Exception exception2 = exception3;
                    CommandProcessorBase.CheckForSevereException(exception2);
                    if (flag)
                    {
                        str1 = this._computerName;
                        goto Label0;
                    }
                    else
                    {
                        string      str2        = StringUtil.Format(ComputerResources.CannotResolveComputerName, this._computerName, exception2.Message);
                        ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str2), "AddressResolutionException", ErrorCategory.InvalidArgument, this._computerName);
                        base.WriteError(errorRecord);
                        str = null;
                    }
                }
                return(str);
            }
Label0:
            bool flag1 = str1.Equals("localhost", StringComparison.OrdinalIgnoreCase);

            if (ComputerWMIHelper.IsComputerNameValid(this._newComputerName))
            {
                return(str1);
            }
            else
            {
                string invalidNewName = ComputerResources.InvalidNewName;
                if (flag1)
                {
                    obj = this._shortLocalMachineName;
                }
                else
                {
                    obj = str1;
                }
                string      str3         = StringUtil.Format(invalidNewName, obj, this._newComputerName);
                ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str3), "InvalidNewName", ErrorCategory.InvalidArgument, this._newComputerName);
                base.WriteError(errorRecord1);
                return(null);
            }
        }
        private void DoRenameComputerAction(string computer, string newName, bool isLocalhost)
        {
            string             str;
            string             userName;
            string             stringFromSecureString;
            EnumerationOptions enumerationOption = new EnumerationOptions();

            enumerationOption.UseAmendedQualifiers = true;
            enumerationOption.DirectRead           = true;
            EnumerationOptions enumerationOption1 = enumerationOption;
            ObjectQuery        objectQuery        = new ObjectQuery("select * from Win32_ComputerSystem");
            bool flag = false;

            if (isLocalhost)
            {
                str = this._shortLocalMachineName;
            }
            else
            {
                str = computer;
            }
            string str1 = str;

            if (base.ShouldProcess(str1))
            {
                if (newName != null && newName.Length > 15)
                {
                    string str2 = newName.Substring(0, 15);
                    string str3 = StringUtil.Format(ComputerResources.TruncateNetBIOSName, str2);
                    string truncateNetBIOSNameCaption = ComputerResources.TruncateNetBIOSNameCaption;
                    if (!this.Force && !base.ShouldContinue(str3, truncateNetBIOSNameCaption))
                    {
                        return;
                    }
                }
                ConnectionOptions connectionOption = new ConnectionOptions();
                connectionOption.Authentication   = AuthenticationLevel.PacketPrivacy;
                connectionOption.Impersonation    = ImpersonationLevel.Impersonate;
                connectionOption.EnablePrivileges = true;
                ConnectionOptions password = connectionOption;
                if (!isLocalhost)
                {
                    if (this.LocalCredential == null)
                    {
                        if (this.DomainCredential != null)
                        {
                            //password.SecurePassword = this.DomainCredential.Password;
                            password.Username = this.DomainCredential.UserName;
                        }
                    }
                    else
                    {
                        //password.SecurePassword = this.LocalCredential.Password;
                        password.Username = ComputerWMIHelper.GetLocalAdminUserName(str1, this.LocalCredential);
                    }
                }
                else
                {
                    password.Username = null;
                    //password.SecurePassword = null;
                }
                ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, "\\root\\cimv2"), password);
                try
                {
                    try
                    {
                        this._searcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption1);
                        foreach (ManagementObject managementObject in this._searcher.Get())
                        {
                            string item = (string)managementObject["DNSHostName"];
                            if (!item.Equals(newName, StringComparison.OrdinalIgnoreCase))
                            {
                                string str4 = null;
                                string str5 = null;
                                if ((bool)managementObject["PartOfDomain"])
                                {
                                    if (this.DomainCredential != null)
                                    {
                                        userName = this.DomainCredential.UserName;
                                    }
                                    else
                                    {
                                        userName = null;
                                    }
                                    str4 = userName;
                                    if (this.DomainCredential != null)
                                    {
                                        stringFromSecureString = Utils.GetStringFromSecureString(this.DomainCredential.Password);
                                    }
                                    else
                                    {
                                        stringFromSecureString = null;
                                    }
                                    str5 = stringFromSecureString;
                                }
                                ManagementBaseObject methodParameters = managementObject.GetMethodParameters("Rename");
                                methodParameters.SetPropertyValue("Name", newName);
                                methodParameters.SetPropertyValue("UserName", str4);
                                methodParameters.SetPropertyValue("Password", str5);
                                ManagementBaseObject managementBaseObject = managementObject.InvokeMethod("Rename", methodParameters, null);
                                int num = Convert.ToInt32(managementBaseObject["ReturnValue"], CultureInfo.CurrentCulture);
                                if (num == 0)
                                {
                                    flag = true;
                                }
                                else
                                {
                                    Win32Exception win32Exception = new Win32Exception(num);
                                    object[]       message        = new object[3];
                                    message[0] = str1;
                                    message[1] = newName;
                                    message[2] = win32Exception.Message;
                                    string      str6        = StringUtil.Format(ComputerResources.FailToRename, message);
                                    ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str6), "FailToRenameComputer", ErrorCategory.OperationStopped, str1);
                                    base.WriteError(errorRecord);
                                }
                                if (!this._passThru)
                                {
                                    continue;
                                }
                                base.WriteObject(ComputerWMIHelper.GetRenameComputerStatusObject(num, newName, str1));
                            }
                            else
                            {
                                string      str7         = StringUtil.Format(ComputerResources.NewNameIsOldName, str1, newName);
                                ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str7), "NewNameIsOldName", ErrorCategory.InvalidArgument, newName);
                                base.WriteError(errorRecord1);
                            }
                        }
                        if (flag && this._restart)
                        {
                            object[] objArray = new object[2];
                            objArray[0] = 6;
                            objArray[1] = 0;
                            object[] objArray1 = objArray;
                            RestartComputerCommand.RestartOneComputerUsingDcom(this, isLocalhost, str1, objArray1, password);
                        }
                        if (flag && !this._restart)
                        {
                            base.WriteWarning(StringUtil.Format(ComputerResources.RestartNeeded, null, str1));
                        }
                    }
                    catch (ManagementException managementException1)
                    {
                        ManagementException managementException = managementException1;
                        string      str8         = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, managementException.Message);
                        ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(str8), "RenameComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord2);
                    }
                    catch (COMException cOMException1)
                    {
                        COMException cOMException = cOMException1;
                        string       str9         = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, cOMException.Message);
                        ErrorRecord  errorRecord3 = new ErrorRecord(new InvalidOperationException(str9), "RenameComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord3);
                    }
                    catch (UnauthorizedAccessException unauthorizedAccessException1)
                    {
                        UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                        string      str10        = StringUtil.Format(ComputerResources.FailToConnectToComputer, str1, unauthorizedAccessException.Message);
                        ErrorRecord errorRecord4 = new ErrorRecord(new InvalidOperationException(str10), "RenameComputerException", ErrorCategory.OperationStopped, str1);
                        base.WriteError(errorRecord4);
                    }
                }
                finally
                {
                    this._searcher.Dispose();
                }
                return;
            }
            else
            {
                return;
            }
        }