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; } }