Example #1
0
        /// <summary>
        /// Starts system restore
        /// </summary>
        /// <param name="strDescription">The description of the restore</param>
        /// <param name="rt">The type of restore point</param>
        /// <param name="lSeqNum">Returns the sequence number</param>
        /// <returns>The status of call</returns>
        /// <seealso cref="Use EndRestore() or CancelRestore() to end the system restore"/>
        public static int StartRestore(string strDescription, RestoreType rt, out long lSeqNum)
        {
            RestorePointInfo rpInfo   = new RestorePointInfo();
            STATEMGRSTATUS   rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
            {
                lSeqNum = 0;
                return(-1);
            }

            try
            {
                // Prepare Restore Point
                rpInfo.dwEventType = BeginSystemChange;
                // By default we create a verification system
                rpInfo.dwRestorePtType  = (int)rt;
                rpInfo.llSequenceNumber = 0;
                rpInfo.szDescription    = strDescription;

                SRSetRestorePointW(ref rpInfo, out rpStatus);
            }
            catch (DllNotFoundException)
            {
                lSeqNum = 0;
                return(-1);
            }

            lSeqNum = rpStatus.llSequenceNumber;

            return(rpStatus.nStatus);
        }
Example #2
0
        /// <summary>
        /// Cancels restore call
        /// </summary>
        /// <param name="lSeqNum">The restore sequence number</param>
        /// <returns>The status of call</returns>
        public static int CancelRestore(long lSeqNum)
        {
            RestorePointInfo rpInfo   = new RestorePointInfo();
            STATEMGRSTATUS   rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
            {
                return(-1);
            }

            try
            {
                rpInfo.dwEventType      = EndSystemChange;
                rpInfo.dwRestorePtType  = (int)RestoreType.CancelledOperation;
                rpInfo.llSequenceNumber = lSeqNum;

                SRSetRestorePointW(ref rpInfo, out rpStatus);
            }
            catch (DllNotFoundException)
            {
                return(-1);
            }

            return(rpStatus.nStatus);
        }
Example #3
0
        /// <summary>
        ///     Cancels restore call
        /// </summary>
        /// <param name="lSeqNum">The restore sequence number</param>
        /// <exception cref="System.ComponentModel.Win32Exception">
        ///     Thrown when STATEMGRSTATUS.nStatus doesn't equal 0
        ///     (ERROR_SUCCESS)
        /// </exception>
        internal static void CancelRestore(long lSeqNum)
        {
            var rpInfo   = new RestorePointInfo();
            var rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
            {
                return;
            }

            try
            {
                rpInfo.dwEventType      = EndSystemChange;
                rpInfo.dwRestorePtType  = (int)RestoreType.CancelledOperation;
                rpInfo.llSequenceNumber = lSeqNum;

                SRSetRestorePointW(ref rpInfo, out rpStatus);
            }
            catch (DllNotFoundException)
            {
                rpStatus.nStatus = 2;
            }

            if (rpStatus.nStatus != 0)
            {
                throw new Win32Exception(rpStatus.nStatus);
            }
        }
Example #4
0
        public bool CreateRestorePoint(string RPName)
        {
            try
            {
                RegistryKey SystemRestoreKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore", true);
                SystemRestoreKey.SetValue("SystemRestorePointCreationFrequency", 0, RegistryValueKind.DWord);

                bool             result   = false;
                RESTOREPOINTINFO RPInfo   = new RESTOREPOINTINFO();
                STATEMGRSTATUS   RPStatus = new STATEMGRSTATUS();

                RPInfo.dwEventType      = 100;
                RPInfo.dwRestorePtType  = 16;
                RPInfo.llSequenceNumber = 0;
                RPInfo.szDescription    = RPName;

                result = SRSetRestorePoint(ref RPInfo, ref RPStatus);

                SystemRestoreKey.DeleteValue("SystemRestorePointCreationFrequency");
                return(result);
            }
            catch
            {
                return(false);
            }
        }
Example #5
0
        public static int FirstRunRestore(string strDescription)
        {
            RestorePointInfo rpInfo   = new RestorePointInfo();
            STATEMGRSTATUS   rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
            {
                return(0);
            }

            try
            {
                // Prepare Restore Point
                rpInfo.dwEventType      = BeginSystemChange;
                rpInfo.dwRestorePtType  = (int)RestoreType.FirstRun;
                rpInfo.llSequenceNumber = 0;
                rpInfo.szDescription    = strDescription;

                SRSetRestorePointW(ref rpInfo, out rpStatus);

                EndRestore(rpStatus.llSequenceNumber);
            }
            catch (DllNotFoundException)
            {
                return(0);
            }

            return(rpStatus.nStatus);
        }
Example #6
0
        /// <summary>
        ///     Starts system restore
        ///     Use SysRestore.EndRestore or SysRestore.CancelRestore to end the system restore
        /// </summary>
        /// <param name="description">The description of the restore</param>
        /// <param name="lSeqNum">Returns the sequence number</param>
        /// <exception cref="System.ComponentModel.Win32Exception">
        ///     Thrown when STATEMGRSTATUS.nStatus doesn't equal 0
        ///     (ERROR_SUCCESS)
        /// </exception>
        internal static void StartRestore(string description, out long lSeqNum)
        {
            var rpInfo   = new RestorePointInfo();
            var rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
            {
                lSeqNum = 0;
                return;
            }

            try
            {
                // Prepare Restore Point
                rpInfo.dwEventType = BeginSystemChange;
                // By default we create a verification system
                rpInfo.dwRestorePtType  = (int)RestoreType.Restore;
                rpInfo.llSequenceNumber = 0;
                rpInfo.szDescription    = description;

                SRSetRestorePointW(ref rpInfo, out rpStatus);
            }
            catch (DllNotFoundException)
            {
                rpStatus.nStatus = 2;
            }

            if (rpStatus.nStatus != 0)
            {
                lSeqNum = 0;
                throw new Win32Exception(rpStatus.nStatus);
            }

            lSeqNum = rpStatus.llSequenceNumber;
        }
        /// <summary>
        /// Cancels restore call
        /// </summary>
        /// <param name="lSeqNum">The restore sequence number</param>
        /// <returns>The status of call</returns>
        internal static int CancelRestore( long lSeqNum )
        {
            RestorePointInfo rpInfo = new RestorePointInfo();
                        STATEMGRSTATUS rpStatus = new STATEMGRSTATUS();

                        if ( !SysRestoreAvailable() )
                                return -1;

                        try
                        {
                                rpInfo.dwEventType = EndSystemChange;
                                rpInfo.dwRestorePtType = (int)RestoreType.CancelledOperation;
                                rpInfo.llSequenceNumber = lSeqNum;

                                SRSetRestorePointW( ref rpInfo, out rpStatus );
                        }
                        catch ( DllNotFoundException )
                        {
                                return -1;
                        }

                        return rpStatus.nStatus;
        }
Example #8
0
 internal static extern bool SRSetRestorePointW(ref RestorePointInfo pRestorePtSpec, out STATEMGRSTATUS pSMgrStatus);
        /// <summary>
        /// Starts system restore
        /// </summary>
        /// <param name="strDescription">The description of the restore</param>
        /// <param name="rt">The type of restore point</param>
        /// <param name="lSeqNum">Returns the sequence number</param>
        /// <returns>The status of call</returns>
        /// <seealso cref="Use EndRestore() or CancelRestore() to end the system restore"/>
        internal static int StartRestore( string strDescription, RestoreType rt, out long lSeqNum )
        {
            RestorePointInfo rpInfo = new RestorePointInfo();
                        STATEMGRSTATUS rpStatus = new STATEMGRSTATUS();

                        if ( !SysRestoreAvailable() )
                        {
                                lSeqNum = 0;
                                return -1;
                        }

                        try
                        {
                                // Prepare Restore Point
                                rpInfo.dwEventType = BeginSystemChange;
                                // By default we create a verification system
                                rpInfo.dwRestorePtType = (int)rt;
                                rpInfo.llSequenceNumber = 0;
                                rpInfo.szDescription = strDescription;

                                SRSetRestorePointW( ref rpInfo, out rpStatus );
                        }
                        catch ( DllNotFoundException )
                        {
                                lSeqNum = 0;
                                return -1;
                        }

                        lSeqNum = rpStatus.llSequenceNumber;

                        return rpStatus.nStatus;
        }
 internal static extern bool SRSetRestorePointW( ref RestorePointInfo pRestorePtSpec, out STATEMGRSTATUS pSMgrStatus );
Example #11
0
 static extern bool SRSetRestorePoint(ref RESTOREPOINTINFO SRPInfo, ref STATEMGRSTATUS SRPStatus);
Example #12
0
        public static int FirstRunRestore(string strDescription)
        {
            RestorePointInfo rpInfo = new RestorePointInfo();
            STATEMGRSTATUS rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
                return 0;

            try
            {
                // Prepare Restore Point
                rpInfo.dwEventType = BeginSystemChange;
                rpInfo.dwRestorePtType = (int)RestoreType.FirstRun;
                rpInfo.llSequenceNumber = 0;
                rpInfo.szDescription = strDescription;

                SRSetRestorePointW(ref rpInfo, out rpStatus);

                EndRestore(rpStatus.llSequenceNumber);
            }
            catch (DllNotFoundException)
            {
                return 0;
            }

            return rpStatus.nStatus;
        }
Example #13
0
        /// <summary>
        /// Ends system restore call
        /// </summary>
        /// <param name="lSeqNum">The restore sequence number</param>
        /// <returns>The status of call</returns>
        public static int EndRestore(long lSeqNum)
        {
            RestorePointInfo rpInfo = new RestorePointInfo();
            STATEMGRSTATUS rpStatus = new STATEMGRSTATUS();

            if (!SysRestoreAvailable())
                return 0;

            try
            {
                rpInfo.dwEventType = EndSystemChange;
                rpInfo.llSequenceNumber = lSeqNum;

                SRSetRestorePointW(ref rpInfo, out rpStatus);
            }
            catch (DllNotFoundException)
            {
                return 0;
            }

            return rpStatus.nStatus;
        }
 public void End()
 {
     if (this.set)
     {
         STATEMGRSTATUS status = new STATEMGRSTATUS();
         RestorePointInfo rpi = new RestorePointInfo();
         rpi.dwEventType = EndSystemChange;
         rpi.dwRestorePtType = (int)RestoreType.Checkpoint;
         rpi.llSequenceNumber = this.restoreseq;
         rpi.szDescription = description;
         this.set = SRSetRestorePointW(ref rpi, out status);
     }
 }
 public RestorePoint(string description)
 {
     this.description = description;
     STATEMGRSTATUS status = new STATEMGRSTATUS();
     RestorePointInfo rpi = new RestorePointInfo();
     rpi.dwEventType = BeginSystemChange;
     rpi.dwRestorePtType = (int)RestoreType.Checkpoint;
     rpi.llSequenceNumber = 0;
     rpi.szDescription = description;
     try
     {
         this.set = SRSetRestorePointW(ref rpi, out status);
     }
     catch
     {
         this.set = false;
         Trace.WriteLine("System Restore Point Not Set (System restore points don't exist on sever class versions of Windows)");
     }
     this.restoreseq = status.llSequenceNumber;
 }
Example #16
0
 public RestorePoint(string description)
 {
     this.description = description;
     STATEMGRSTATUS status = new STATEMGRSTATUS();
     RestorePointInfo rpi = new RestorePointInfo();
     rpi.dwEventType = BeginSystemChange;
     rpi.dwRestorePtType = (int)RestoreType.Checkpoint;
     rpi.llSequenceNumber = 0;
     rpi.szDescription = description;
     this.set = SRSetRestorePointW(ref rpi, out status);
     this.restoreseq = status.llSequenceNumber;
 }