Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi System Restore Point erstellen, code geht nicht unter Win10 (https://www.delphipraxis.net/189550-system-restore-point-erstellen-code-geht-nicht-unter-win10.html)

Shark99 23. Jun 2016 14:23

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.

Dalai 23. Jun 2016 14:56

AW: System Restore Point erstellen, code geht nicht unter Win10
 
MSDN sagt zu SRSetRestorePoint:
Zitat:

Remarks
You must initialize COM security to allow NetworkService, LocalService and System to call back into any process that uses SRSetRestorePoint. This is necessary for SRSetRestorePoint to operate properly. For information on setting up the COM calls to CoInitializeEx and CoInitializeSecurity, see Using System Restore.
Übrigens fehlt in deinem Code ein Gegenstück zu LoadLibrary; müsste CloseHandle sein.

MfG Dalai

Shark99 23. Jun 2016 15:46

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.

EWeiss 23. Jun 2016 16:57

AW: System Restore Point erstellen, code geht nicht unter Win10
 
Zitat:

Zitat von Shark99 (Beitrag 1340909)
CoInitializeEx(0, COINIT_MULTITHREADED) hilft leider nicht weiter. Ich lese mich in CoInitializeSecurity, scheint nicht Trivial zu sein.

Com und Delphi ist wie Katz und Hund.
Bist sicher das CoInitializeEx auch 0 ist?

gruss

Der schöne Günther 23. Jun 2016 17:26

AW: System Restore Point erstellen, code geht nicht unter Win10
 
Zitat:

Zitat von Shark99 (Beitrag 1340909)
CoInitializeSecurity, scheint nicht Trivial zu sein.

Hatte vorhin auch geschaut ob ich irgendwie schlau sein und helfen kann und dann dachte ich auch: :shock:

hoika 24. Jun 2016 06:54

AW: System Restore Point erstellen, code geht nicht unter Win10
 
Hallo,

schau mal hier

http://www.delphipraxis.net/1211700-post7.html

Heiko

Erdbär 24. Jun 2016 15:08

AW: System Restore Point erstellen, code geht nicht unter Win10
 
Die Erinnerung verblasst immer mehr, aber InnoSetup kann RestorePoints erstellen:

Delphi-Quellcode:
[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;
Den InnoCode habe ich vermutlich aus diversen Foren (Inno/SO) heruntergeladen und angepasst, ein paar END;s sind vermutlich zu viel :oops:

Gelegentlich schaue/schlage ich bei Jordan Russell einfach mal nach :wink:

full stop / period


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz