jwasrrestoreptapi.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. {******************************************************************************}
  2. { }
  3. { Windows System Restore API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: srrestoreptapi.h, released Match 2003. The original }
  9. { Pascal code is: SrRestorePtApi.pas, released December 2000. }
  10. { The initial developer of the Pascal code is Marcel van Brakel }
  11. { (brakelm att chello dott nl). }
  12. { }
  13. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  14. { Marcel van Brakel. All Rights Reserved. }
  15. { }
  16. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  17. { }
  18. { You may retrieve the latest version of this file at the Project JEDI }
  19. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  20. { }
  21. { The contents of this file are used with permission, subject to the Mozilla }
  22. { Public License Version 1.1 (the "License"); you may not use this file except }
  23. { in compliance with the License. You may obtain a copy of the License at }
  24. { http://www.mozilla.org/MPL/MPL-1.1.html }
  25. { }
  26. { Software distributed under the License is distributed on an "AS IS" basis, }
  27. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  28. { the specific language governing rights and limitations under the License. }
  29. { }
  30. { Alternatively, the contents of this file may be used under the terms of the }
  31. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  32. { provisions of the LGPL License are applicable instead of those above. }
  33. { If you wish to allow use of your version of this file only under the terms }
  34. { of the LGPL License and not to allow others to use your version of this file }
  35. { under the MPL, indicate your decision by deleting the provisions above and }
  36. { replace them with the notice and other provisions required by the LGPL }
  37. { License. If you do not delete the provisions above, a recipient may use }
  38. { your version of this file under either the MPL or the LGPL License. }
  39. { }
  40. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  41. { }
  42. {******************************************************************************}
  43. unit JwaSrRestorePtApi;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "SrRestorePtApi.h"'}
  47. {$HPPEMIT ''}
  48. {$I jediapilib.inc}
  49. interface
  50. uses
  51. JwaWinNT, JwaWinType;
  52. //
  53. // Type of Event
  54. //
  55. const
  56. MIN_EVENT = 100;
  57. {$EXTERNALSYM MIN_EVENT}
  58. BEGIN_SYSTEM_CHANGE = 100;
  59. {$EXTERNALSYM BEGIN_SYSTEM_CHANGE}
  60. END_SYSTEM_CHANGE = 101;
  61. {$EXTERNALSYM END_SYSTEM_CHANGE}
  62. BEGIN_NESTED_SYSTEM_CHANGE = 102; // for Whistler only - use this to prevent nested restore pts
  63. {$EXTERNALSYM BEGIN_NESTED_SYSTEM_CHANGE}
  64. END_NESTED_SYSTEM_CHANGE = 103; // for Whistler only - use this to prevent nested restore pts
  65. {$EXTERNALSYM END_NESTED_SYSTEM_CHANGE}
  66. MAX_EVENT = 103;
  67. {$EXTERNALSYM MAX_EVENT}
  68. //
  69. // Type of Restore Points
  70. //
  71. MIN_RPT = 0;
  72. {$EXTERNALSYM MIN_RPT}
  73. APPLICATION_INSTALL = 0;
  74. {$EXTERNALSYM APPLICATION_INSTALL}
  75. APPLICATION_UNINSTALL = 1;
  76. {$EXTERNALSYM APPLICATION_UNINSTALL}
  77. DESKTOP_SETTING = 2; // Not implemented
  78. {$EXTERNALSYM DESKTOP_SETTING}
  79. ACCESSIBILITY_SETTING = 3; // Not implemented
  80. {$EXTERNALSYM ACCESSIBILITY_SETTING}
  81. OE_SETTING = 4; // Not implemented
  82. {$EXTERNALSYM OE_SETTING}
  83. APPLICATION_RUN = 5; // Not implemented
  84. {$EXTERNALSYM APPLICATION_RUN}
  85. RESTORE = 6;
  86. {$EXTERNALSYM RESTORE}
  87. CHECKPOINT = 7;
  88. {$EXTERNALSYM CHECKPOINT}
  89. WINDOWS_SHUTDOWN = 8; // Not implemented
  90. {$EXTERNALSYM WINDOWS_SHUTDOWN}
  91. WINDOWS_BOOT = 9; // Not implemented
  92. {$EXTERNALSYM WINDOWS_BOOT}
  93. DEVICE_DRIVER_INSTALL = 10;
  94. {$EXTERNALSYM DEVICE_DRIVER_INSTALL}
  95. FIRSTRUN = 11;
  96. {$EXTERNALSYM FIRSTRUN}
  97. MODIFY_SETTINGS = 12;
  98. {$EXTERNALSYM MODIFY_SETTINGS}
  99. CANCELLED_OPERATION = 13; // Only valid for END_SYSTEM_CHANGE
  100. {$EXTERNALSYM CANCELLED_OPERATION}
  101. BACKUP_RECOVERY = 14;
  102. {$EXTERNALSYM BACKUP_RECOVERY}
  103. MAX_RPT = 14;
  104. {$EXTERNALSYM MAX_RPT}
  105. MAX_DESC = 64;
  106. {$EXTERNALSYM MAX_DESC}
  107. MAX_DESC_W = 256; // longer for Whistler
  108. {$EXTERNALSYM MAX_DESC_W}
  109. //
  110. // for Millennium compatibility
  111. //
  112. //#pragma pack(push, srrestoreptapi_include)
  113. //#pragma pack(1)
  114. //
  115. // Restore point information
  116. //
  117. type
  118. _RESTOREPTINFOA = packed record
  119. dwEventType: DWORD; // Type of Event - Begin or End
  120. dwRestorePtType: DWORD; // Type of Restore Point - App install/uninstall
  121. llSequenceNumber: Int64; // Sequence Number - 0 for begin
  122. szDescription: array [0..MAX_DESC - 1] of Char; // Description - Name of Application / Operation
  123. end;
  124. {$EXTERNALSYM _RESTOREPTINFOA}
  125. RESTOREPOINTINFOA = _RESTOREPTINFOA;
  126. {$EXTERNALSYM RESTOREPOINTINFOA}
  127. PRESTOREPOINTINFOA = ^RESTOREPOINTINFOA;
  128. {$EXTERNALSYM PRESTOREPOINTINFOA}
  129. TRestorePointInfoA = RESTOREPOINTINFOA;
  130. _RESTOREPTINFOW = packed record
  131. dwEventType: DWORD; // Type of Event - Begin or End
  132. dwRestorePtType: DWORD; // Type of Restore Point - App install/uninstall
  133. llSequenceNumber: Int64; // Sequence Number - 0 for begin
  134. szDescription: array [0..MAX_DESC_W - 1] of WideChar; // Description - Name of Application / Operation
  135. end;
  136. {$EXTERNALSYM _RESTOREPTINFOW}
  137. RESTOREPOINTINFOW = _RESTOREPTINFOW;
  138. {$EXTERNALSYM RESTOREPOINTINFOW}
  139. PRESTOREPOINTINFOW = ^RESTOREPOINTINFOW;
  140. {$EXTERNALSYM PRESTOREPOINTINFOW}
  141. TRestorePointInfoW = RESTOREPOINTINFOW;
  142. {$IFDEF UNICODE}
  143. RESTOREPOINTINFO = RESTOREPOINTINFOW;
  144. {$EXTERNALSYM RESTOREPOINTINFO}
  145. PRESTOREPOINTINFO = PRESTOREPOINTINFOW;
  146. {$EXTERNALSYM PRESTOREPOINTINFO}
  147. TRestorePointInfo = TRestorePointInfoW;
  148. {$ELSE}
  149. RESTOREPOINTINFO = RESTOREPOINTINFOA;
  150. {$EXTERNALSYM RESTOREPOINTINFO}
  151. PRESTOREPOINTINFO = PRESTOREPOINTINFOA;
  152. {$EXTERNALSYM PRESTOREPOINTINFO}
  153. TRestorePointInfo = TRestorePointInfoA;
  154. {$ENDIF UNICODE}
  155. //
  156. // Status returned by System Restore
  157. //
  158. _SMGRSTATUS = packed record
  159. nStatus: DWORD; // Status returned by State Manager Process
  160. llSequenceNumber: Int64; // Sequence Number for the restore point
  161. end;
  162. {$EXTERNALSYM _SMGRSTATUS}
  163. STATEMGRSTATUS = _SMGRSTATUS;
  164. {$EXTERNALSYM STATEMGRSTATUS}
  165. PSTATEMGRSTATUS = ^STATEMGRSTATUS;
  166. {$EXTERNALSYM PSTATEMGRSTATUS}
  167. TSMgrStatus = STATEMGRSTATUS;
  168. //#pragma pack(pop, srrestoreptapi_include)
  169. //
  170. // RPC call to set a restore point
  171. //
  172. // Return value TRUE if the call was a success
  173. // FALSE if the call failed
  174. //
  175. // If pSmgrStatus nStatus field is set as follows
  176. //
  177. // ERROR_SUCCESS If the call succeeded (return value will be TRUE)
  178. //
  179. // ERROR_TIMEOUT If the call timed out due to a wait on a mutex for
  180. // for setting restore points.
  181. //
  182. // ERROR_INVALID_DATA If the cancel restore point is called with an invalid
  183. // sequence number
  184. //
  185. // ERROR_INTERNAL_ERROR If there are internal failures.
  186. //
  187. // ERROR_BAD_ENVIRONMENT If the API is called in SafeMode
  188. //
  189. // ERROR_SERVICE_DISABLED If SystemRestore is Disabled.
  190. //
  191. // ERROR_DISK_FULL If System Restore is frozen (Windows Whistler only)
  192. //
  193. // ERROR_ALREADY_EXISTS If this is a nested restore point
  194. function SRSetRestorePointA(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus: PSTATEMGRSTATUS): BOOL stdcall;
  195. {$EXTERNALSYM SRSetRestorePointA}
  196. function SRSetRestorePointW(pRestorePtSpec: PRESTOREPOINTINFOW; pSMgrStatus: PSTATEMGRSTATUS): BOOL stdcall;
  197. {$EXTERNALSYM SRSetRestorePointW}
  198. function SRRemoveRestorePoint(dwRPNum: DWORD): DWORD; stdcall;
  199. {$EXTERNALSYM SRRemoveRestorePoint}
  200. function SRSetRestorePoint(pRestorePtSpec: PRESTOREPOINTINFO; pSMgrStatus: PSTATEMGRSTATUS): BOOL stdcall;
  201. {$EXTERNALSYM SRSetRestorePoint}
  202. implementation
  203. const
  204. srclient = 'srclient.dll';
  205. {$IFDEF UNICODE}
  206. AWSuffix = 'W';
  207. {$ELSE}
  208. AWSuffix = 'A';
  209. {$ENDIF UNICODE}
  210. {$IFDEF DYNAMIC_LINK}
  211. var
  212. _SRSetRestorePointA: Pointer;
  213. function SRSetRestorePointA;
  214. begin
  215. GetProcedureAddress(_SRSetRestorePointA, srclient, 'SRSetRestorePointA');
  216. asm
  217. MOV ESP, EBP
  218. POP EBP
  219. JMP [_SRSetRestorePointA]
  220. end;
  221. end;
  222. var
  223. _SRSetRestorePointW: Pointer;
  224. function SRSetRestorePointW;
  225. begin
  226. GetProcedureAddress(_SRSetRestorePointW, srclient, 'SRSetRestorePointW');
  227. asm
  228. MOV ESP, EBP
  229. POP EBP
  230. JMP [_SRSetRestorePointW]
  231. end;
  232. end;
  233. var
  234. _SRSetRestorePoint: Pointer;
  235. function SRSetRestorePoint;
  236. begin
  237. GetProcedureAddress(_SRSetRestorePoint, srclient, 'SRSetRestorePoint' + AWSuffix);
  238. asm
  239. MOV ESP, EBP
  240. POP EBP
  241. JMP [_SRSetRestorePoint]
  242. end;
  243. end;
  244. var
  245. _SRRemoveRestorePoint: Pointer;
  246. function SRRemoveRestorePoint;
  247. begin
  248. GetProcedureAddress(_SRRemoveRestorePoint, srclient, 'SRRemoveRestorePoint');
  249. asm
  250. MOV ESP, EBP
  251. POP EBP
  252. JMP [_SRRemoveRestorePoint]
  253. end;
  254. end;
  255. {$ELSE}
  256. function SRSetRestorePointA; external srclient name 'SRSetRestorePointA';
  257. function SRSetRestorePointW; external srclient name 'SRSetRestorePointW';
  258. function SRSetRestorePoint; external srclient name 'SRSetRestorePointW' + AWSuffix;
  259. function SRRemoveRestorePoint; external srclient name 'SRRemoveRestorePoint';
  260. {$ENDIF DYNAMIC_LINK}
  261. end.