March 28, 2024, 06:14:02 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Restore point creation not working any more

Started by Andy, October 12, 2017, 04:48:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

October 12, 2017, 04:48:04 AM Last Edit: October 12, 2017, 05:13:01 AM by Andy
I thought it would be a nice safety option in my reg viewer program to include creating a system restore point, so I revisited the bit code the great (sadly missed) Sapero wrote.

Now it used to work in XP - if I remember correctly - but it doesn't now?

As far as I can tell, and according to msdn the code is going through the process of creating a new restore point, it even returns zero (ERROR_SUCCESS) status at the end along with the new restore point number.

BUT - when I check out system restore, the restore point isn't listed.  ???

I've tried running it as Admin, even logging off and logging into the Admin user account still shows the same problem.

Any ideas what it could be, and is there a way to list restore points ourselves?

Here is the code, try it:

$include "windowssdk.inc"
$include "SrRestorePtApi.inc"

int retval = 0
RESTOREPOINTINFO rpi
STATEMGRSTATUS   sms

openconsole
print
print "Creating restore point"
print
retval = CreateRP("My restore point")
print
print sms.nStatus
print
print "  End of restore point creation, Restore point number is ",retval
print
do:until inkey$ <> ""
closeconsole
end


sub CreateRP(string Description),DWORD

' returns the number xxx in \System Volume Information\_restore{machine_guid}\RPxxx
DWORD seq = 0

rpi.dwEventType      = BEGIN_SYSTEM_CHANGE ' APPLICATION_INSTALL APPLICATION_UNINSTALL DEVICE_DRIVER_INSTALL CANCELLED_OPERATION 
rpi.dwRestorePtType  = MODIFY_SETTINGS
rpi.llSequenceNumber = 0q ' put here an unique value

lstrcpyn(rpi.szDescription, Description, MAX_DESC)
rpi.szDescription[MAX_DESC-1] = 0

if (!SRSetRestorePoint(&rpi, &sms))

if (sms.nStatus = ERROR_SERVICE_DISABLED)

'ask("Would you like to start the service?")
'return on cancel
'EnableSystemRestore()
'SRSetRestorePoint(&rpi, &sms)
'return on failure
else
'show error
ShowSrError(sms)
return 0
endif

endif

' do your file/registry changes here, if any

seq                  = sms.llSequenceNumber
rpi.llSequenceNumber = sms.llSequenceNumber
rpi.dwEventType      = END_SYSTEM_CHANGE

if (!SRSetRestorePoint(&rpi, &sms))

'Failed to close restore point seq
ShowSrError(sms)
SRRemoveRestorePoint(seq)
seq = 0
endif

if (seq)
'created restore point seq, Description
endif

return seq
endsub


sub ShowSrError(STATEMGRSTATUS sms)

select (sms.nStatus)
case ERROR_BAD_ENVIRONMENT  :print "The function was called in safe mode"
case ERROR_DISK_FULL        :print "System Restore is in standby mode because disk space is low"
case ERROR_INTERNAL_ERROR   :print "An internal error occurred"
case ERROR_SERVICE_DISABLED :print "System Restore is disabled"
case ERROR_TIMEOUT          :print "The call timed out due to a wait on a mutex for setting restore points"
default                     :print "error ", sms.nStatus
endselect
endsub


I've even dug out my old copy of Ebasic, which is what I was using in my XP days, yet still the same result - RP not listed.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

That's a COM func, call CoInitialize(0) when the program start & CoUninitialize() before end statement.

Andy

October 12, 2017, 11:23:05 PM #2 Last Edit: October 13, 2017, 12:29:46 AM by Andy
Nope, tried that, they are not showing up as restore points which is a shame.

Anyone still using XP? if so can you try the code for me please.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

I have no idea why but it worked for me yesterday (64-bit win10). I'll explain roughly what I did

- Added CoInitialize(0) below the inclusions and CoUninitialize() above END statement, ran the code and it returns 5 - access denied.
- Right-clicked on the executable, and with "Run as administrator" option selected the restore point was created successfully.

Today is not working, but according to msdn
https://msdn.microsoft.com/en-us/library/windows/desktop/aa378727(v=vs.85).aspx

QuoteIf an application calls the SRSetRestorePoint function to create a restore point, Windows skips creating this new restore point if any restore points have been created in the last 24 hours.