![]() |
System Restore Point erstellen, code geht nicht unter Win10
Liste der Anhänge anzeigen (Anzahl: 1)
Dieser Code funktioniert unter Windows 2000 bis Windows 7 um einen System Restore Wiederherstellungspunkt zu erzeugen. Dazu braucht man natürlich Admin-Rechte. Unter Windows 10 funktioniert der Code leider nicht. Es wird zwar success gemeldet, aber kein Wiederherstellungspunkt wird erstellt. Ich hoffe jemand weiß woran es liegt. Ich habe ein Beispielprojekt angehängt.
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Forms, Classes, SysUtils, Controls, StdCtrls; const // Type of Event BEGIN_SYSTEM_CHANGE = 100; END_SYSTEM_CHANGE = 101; // Type of Restore Points APPLICATION_INSTALL = 0; CANCELLED_OPERATION = 13; MAX_DESC = 64; MIN_EVENT = 100; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; // Restore point information PRESTOREPTINFOA = ^_RESTOREPTINFOA; _RESTOREPTINFOA = packed record dwEventType: DWORD; // Type of Event - Begin or End dwRestorePtType: DWORD; // Type of Restore Point - App install/uninstall llSequenceNumber: INT64; // Sequence Number - 0 for begin szDescription: array [0..MAX_DESC] of CHAR; // Description - Name of Application / Operation end; RESTOREPOINTINFO = _RESTOREPTINFOA; PRESTOREPOINTINFOA = ^_RESTOREPTINFOA; // Status returned by System Restore PSMGRSTATUS = ^_SMGRSTATUS; _SMGRSTATUS = packed record nStatus: DWORD; // Status returned by State Manager Process llSequenceNumber: INT64; // Sequence Number for the restore point end; STATEMGRSTATUS = _SMGRSTATUS; PSTATEMGRSTATUS = ^_SMGRSTATUS; TSetRestorePoint = Function(pRestorePtSpec: PRESTOREPOINTINFOA; pSMgrStatus: PSTATEMGRSTATUS): Bool; stdcall; function CreateRestorePoint(s: string): boolean; var hSrClientDLL : THandle; FSetRestorePoint : TSetRestorePoint; Form1: TForm1; implementation {$R *.dfm} function CreateRestorePoint(s: string): boolean; var RestorePtSpec: RESTOREPOINTINFO; SMgrStatus: STATEMGRSTATUS; begin Result := False; 23.06.2016 if not assigned(FSetRestorePoint) then begin hSrClientDLL := LoadLibrary('SrClient.dll'); if hSrClientDLL = 0 then Exit; @FSetRestorePoint := GetProcAddress(hSrClientDLL, 'SRSetRestorePointA'); if not assigned(FSetRestorePoint) then Exit; end; RestorePtSpec.dwEventType := BEGIN_SYSTEM_CHANGE; RestorePtSpec.dwRestorePtType := APPLICATION_INSTALL; RestorePtSpec.llSequenceNumber := 0; copymemory(@RestorePtSpec.szDescription[low(RestorePtSpec.szDescription)],@s[1],sizeof(RestorePtSpec.szDescription)); if FSetRestorePoint(@RestorePtSpec, @SMgrStatus) then begin Result := True; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if CreateRestorePoint('Test Restore Point') then Caption := 'success' else Caption := 'Error'; end; end. |
AW: System Restore Point erstellen, code geht nicht unter Win10
![]() Zitat:
MfG Dalai |
AW: System Restore Point erstellen, code geht nicht unter Win10
CoInitializeEx(0, COINIT_MULTITHREADED) hilft leider nicht weiter. Ich lese mich in CoInitializeSecurity, scheint nicht Trivial zu sein.
|
AW: System Restore Point erstellen, code geht nicht unter Win10
Zitat:
Bist sicher das CoInitializeEx auch 0 ist? gruss |
AW: System Restore Point erstellen, code geht nicht unter Win10
Zitat:
|
AW: System Restore Point erstellen, code geht nicht unter Win10
|
AW: System Restore Point erstellen, code geht nicht unter Win10
Die Erinnerung verblasst immer mehr, aber InnoSetup kann RestorePoints erstellen:
Delphi-Quellcode:
Den InnoCode habe ich vermutlich aus diversen Foren (Inno/SO) heruntergeladen und angepasst, ein paar END;s sind vermutlich zu viel :oops:
[Code]
//Code to create a restore point on XP and later const // RestorePointTypes APPLICATION_INSTALL = 0; APPLICATION_UNINSTALL = 1; DEVICE_DRIVER_INSTALL = 10; MODIFY_SETTINGS = 12; CANCELLED_OPERATION = 13; // EventTypes BEGIN_SYSTEM_CHANGE = 100; END_SYSTEM_CHANGE = 101; BEGIN_NESTED_SYSTEM_CHANGE = 102; END_NESTED_SYSTEM_CHANGE = 103; function createRestorePoint(RestoreName : String; RestorePointType, EventType : Integer): boolean; var ScriptControl, sr: Variant; begin ScriptControl := CreateOleObject('ScriptControl'); ScriptControl.Language := 'VBScript'; sr := ScriptControl.Eval('getobject("winmgmts:\\.\root\default:Systemrestore")'); Result := (sr.CreateRestorePoint(RestoreName, RestorePointType, EventType) = 0); end; procedure AskRestorePoint(); var s:String; begin s:='Es wird dringend empfohlen, einen Systemwiederherstellungspunkt zu erstellen, '; s:=s+'was die Installation allerdings um einige Sekunden verzögert.'+#13#10#13#10; s:=s+'Möchten Sie das?'; if GetWindowsVersion >= $05010000 then begin if msgbox(s,mbconfirmation, mb_yesno) = idyes then begin if createRestorePoint('Installation von Meinem tollen Programm hier und heute', APPLICATION_INSTALL, BEGIN_SYSTEM_CHANGE) then end; end; end; Gelegentlich schaue/schlage ich bei Jordan Russell einfach mal nach :wink: full stop / period |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz