示例#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);
        }
示例#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);
        }
示例#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);
            }
        }
示例#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);
            }
        }
示例#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);
        }
示例#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;
        }
示例#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 );
示例#11
0
 static extern bool SRSetRestorePoint(ref RESTOREPOINTINFO SRPInfo, ref STATEMGRSTATUS SRPStatus);
示例#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;
        }
示例#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;
        }
示例#14
0
 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);
     }
 }
示例#15
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;
     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;
 }
示例#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;
 }