Create Restore Point


Jump to: navigation, search


Creating a Restore Point

by Kevin Provance


Inno's GetActiveOleObject method is the closest there is to GetObject, but it does not allow you to specify the path, only the class name. So we cannot use the WmiService which needs to pass a path. Therefore we need to create a ScriptControl (msscript.ocx). This control is included with the Windows operating system, version 2000 through Win7. Older operating systems to not include the script control.

Msscript.ocx is installed with Visual Studio 6 (I'm not certain about newer versions of Visual Studio) but there is some debate about whether or not the actual control is redistributable. It is not included in the redist.exe, so we must assume it is not redistributable as is.

In the event support for operating systems older than Windows 2000 is necessary, Microsoft offers an installer for the msscript.ocx control. It can be downloaded here:

Windows Script Control:

Since older operating systems do not support restore points, the whole redist issue might seem moot. Perhaps. But the WMI contains many more features than could be used with older operating systems, and this information might be useful for those who wish to use WMI with Inno.


I've created this procedure to keep the bulk of the code in one place, for use in different scripts.

function CreateRestorePoint(sDescription: String): Integer;
   ScriptControl:  Variant;
   oWMI:     	   Variant;
   ErrCode:  	   Integer;

   // Create the ScriptControl object.
   ScriptControl := CreateOleObject('ScriptControl');
   // Set the Language property (VBScript or JavaScript)
   ScriptControl.Language := 'VBScript';
   // Now create the WMI object we could not with straight Pascal code.
   oWMI := ScriptControl.Eval('GetObject("winmgmts:\\.\root\default:Systemrestore")');
   // Create the restore point.
   ErrCode := oWMI.CreateRestorePoint(sDescription, 0, 100);
   // Return the error code, if any.  A value of zero indicates success. 
   Result := (ErrCode = 0);


Now all you need do is call the procedure. The only information you need to pass is whatever you would like to show in the System Restore window.

    bResult: Boolean;
    bResult := CreateRestorePoint ('My App Installation');
    // Handle the return value as you see fit.
    If bResult then begin
       Msgbox ('Create restore point succeeded.', mbInformation, MB_OK);     
    end else begin
       Msgbox ('Create restore point failed.', mbInformation, MB_OK);

Kevin Provance 07:43, 20 January 2011 (UTC)

Links and References

Personal tools