Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a System Restore Point Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
21-Jul-03
Category
System
Language
Delphi 3.x
Views
161
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Yoav Abrahami 

The following example demonstrates how to create and cancel restore points.

Answer:

To create a new System Restore Point in Windows XP, click Start -> All Programs -> 
Accessories -> System Tools -> System Restore. 

The following two examples show two ways how to do this with Delphi. 
1   
2   {*****************************************************}
3   {1. Using the Microsoft Scripting Control}
4   
5     {
6     If you haven't installed the Microsoft Scripting Control yet
7     (TScriptControl component), get it
8     from http://www.msdn.microsoft.com/scripting/
9   
10    Once you've downloaded and run the installation, start Delphi and go to the
11    Component | Import ActiveX Control... menu.
12    Select "Microsoft Script Control 1.0" from the Listbox amd click "Install"
13    to install the component into Delphi's palette.
14    What you should end up with now is a TScriptControl component on your ActiveX tab.
15    Start a new application, and drop a TButton, and a 
16    TScriptControl onto the main form.
17    In the OnClick event of Button1, put the following code:
18    }
19  
20  procedure TForm1.Button1Click(Sender: TObject);
21  var
22    sr: OLEVAriant;
23  begin
24    ScriptControl1.Language := 'VBScript';
25    sr := ScriptControl1.Eval('getobject("winmgmts:\\.\root\default:Systemrestore")');
26    if sr.CreateRestorePoint('Automatic Restore Point', 0, 100) = 0 then
27      ShowMessage('New Restore Point successfully created.')
28    else
29      ShowMessage('Restore Point creation Failed!');
30  end;
31  
32  {*****************************************************}
33  {2. Using the SRSetRestorePoint() API from SrClient.dll}
34  
35  // Translation from SRRestorePtAPI.h
36  const
37    // Type of Event
38    BEGIN_SYSTEM_CHANGE = 100;
39    END_SYSTEM_CHANGE = 101;
40    // Type of Restore Points
41    APPLICATION_INSTALL = 0;
42    CANCELLED_OPERATION = 13;
43    MAX_DESC = 64;
44    MIN_EVENT = 100;
45  
46    // Restore point information
47  type
48    PRESTOREPTINFOA = ^_RESTOREPTINFOA;
49    _RESTOREPTINFOA = packed record
50      dwEventType: DWORD; // Type of Event - Begin or End
51      dwRestorePtType: DWORD; // Type of Restore Point - App install/uninstall
52      llSequenceNumber: INT64; // Sequence Number - 0 for begin
53      szDescription: array[0..MAX_DESC] of CHAR;
54        // Description - Name of Application / Operation
55    end;
56    RESTOREPOINTINFO = _RESTOREPTINFOA;
57    PRESTOREPOINTINFOA = ^_RESTOREPTINFOA;
58  
59    // Status returned by System Restore
60  
61    PSMGRSTATUS = ^_SMGRSTATUS;
62    _SMGRSTATUS = packed record
63      nStatus: DWORD; // Status returned by State Manager Process
64      llSequenceNumber: INT64; // Sequence Number for the restore point
65    end;
66    STATEMGRSTATUS = _SMGRSTATUS;
67    PSTATEMGRSTATUS = ^_SMGRSTATUS;
68  
69  function SRSetRestorePointA(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus:
70    PSTATEMGRSTATUS): Bool;
71    stdcall; external 'SrClient.dll' Name 'SRSetRestorePointA';
72  
73  // Example how to create and cancel a previous restore point.
74  // Ref: http://tinyurl.com/78pv
75  
76  procedure TForm1.Button1Click(Sender: TObject);
77  const
78    CR = #13#10;
79  var
80    RestorePtSpec: RESTOREPOINTINFO;
81    SMgrStatus: STATEMGRSTATUS;
82  begin
83    // Initialize the RESTOREPOINTINFO structure
84    RestorePtSpec.dwEventType := BEGIN_SYSTEM_CHANGE;
85    RestorePtSpec.dwRestorePtType := APPLICATION_INSTALL;
86    RestorePtSpec.llSequenceNumber := 0;
87    RestorePtSpec.szDescription := 'SAMPLE RESTORE POINT';
88  
89    if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
90    begin
91      ShowMessage('Restore point set. Restore point data:' + CR +
92        'Sequence Number: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR +
93        'Status: ' + Format('%u', [SMgrStatus.nStatus]));
94  
95      // Restore Point Spec to cancel the previous restore point.
96      RestorePtSpec.dwEventType := END_SYSTEM_CHANGE;
97      RestorePtSpec.dwRestorePtType := CANCELLED_OPERATION;
98      RestorePtSpec.llSequenceNumber := SMgrStatus.llSequenceNumber;
99  
100     // This is the sequence number returned by the previous call.
101     // Canceling the previous restore point
102     if (SRSetRestorePointA(@RestorePtSpec, @SMgrStatus)) then
103       ShowMessage('Restore point canceled. Restore point data:' + CR +
104         'Sequence Number: ' + Format('%d', [SMgrStatus.llSequenceNumber]) + CR +
105         'Status: ' + Format('%u', [SMgrStatus.nStatus]))
106 
107     else
108       ShowMessage('Couldn''t cancel restore point.');
109   end
110   else
111     ShowMessage('Couldn''t set restore point.');
112 end;
113 end;



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC