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;
            }
        }
 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;
     }
 }
 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;
     }
 }
Exemplo n.º 4
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;
     }
 }