Enable System Restore and Set Value for Drive %

I have looked to see if this already exists but haven’t been able to find it. I would like a script that will enable system restore and set the value of percent of the drive to use.

Then if possible create a restore point. I’m sure there’s a separate script I can run for that if not.

Hi @mathew.gaudieri

We’ll progress with your request and update you once it has been completed.

Thank you

Hello @matthew.hedtcke,

Please refer to the link below for the script that will enable the system restore. The script works well in windows 8.1 and 10.

https://scripts.comodo.com/frontend/web/topic/enable-system-restore

Edit Parameters:
drive=“c:” #Provide the drive which you need to enable Restore Access

Thank you and please let us if the script works for you, looking forward to your response.

The script works great. Is there a way to set the value of drive percentage? Looks like default its set to 4%

Hi @matthew.hedtcke

We are progressing the set value drive script, will update you once it has been completed.

Thank you

Hi @matthew.hedtcke

please refer the JSON file to set the value of drive percentage
20180404-Set-the-value-of-percent-of-the-drive-to-use.json

Please let us know if the script works for you, looking forward to your response.

20180404-Set-the-value-of-percent-of-the-drive-to-use.json (2.33 KB)

It worked perfectly. Thanks so much!

@Matthew ,

Thank you for giving us a response. We appreciate your feedback

2 things though, if system restore is already enabled or the value is already set to the set percentage it errors our with the message below. A little confusing because the error reports it cant find a file and in my research I figured out that those settings were already enabled.

Type of ticket creator: PROCEDURE
Event Created at: Wed Apr 04 13:38:38 2018 GMT+0
Device Name: XXX
Logged on User: XXX
Data: Traceback (most recent call last):
File “”, line 52, in
WindowsError: [Error 2] The system cannot find the file specified: ‘C:\WINDOWS\TEMP\powershell_file.ps1’

Hello @matthew.hedtcke,

We have forwarded your feedback to our development team. We will reach back to you via email.

Thank you for your patience.

Hi @matthew.hedtcke

We will analyze and modify the script as per your request.

Thank you

2 things though, if system restore is already enabled or the value is already set to the set percentage it errors our with the message below. A little confusing because the error reports it cant find a file and in my research I figured out that those settings were already enabled.

Type of ticket creator: PROCEDURE
Event Created at: Wed Apr 04 13:38:38 2018 GMT+0
Device Name: XXX
Logged on User: XXX
Data: Traceback (most recent call last):
File “”, line 52, in
WindowsError: [Error 2] The system cannot find the file specified: ‘C:\WINDOWS\TEMP\powershell_file.ps1’

Hi @matthew.hedtcke

Refer this modified script to enable the System restore and set the value of percent of the drive to use,

Please let us know if the script works for you, looking forward to your response.

Note:

Run as System User

Thank you

20180405-Enable-the-System-restore-and-set-the-value-of-percent-of-the-drive-to-use.json (4.49 KB)

This is the error this script is giving.

Type of ticket creator: PROCEDURE
Event Created at: Fri Jul 20 20:35:32 2018 GMT+0
Device Name: XXXX
Logged on User: XXXX
Data: Traceback (most recent call last):
File “”, line 90, in
File “”, line 71, in disable
NameError: global name ‘file_name’ is not defined

drive=“c:” #Provide the drive which you need to enable Restore Access
drive_percentage=‘10%’ #Provide the percentage which you need to set

import subprocess
import os
import ctypes
cmd=“vssadmin List ShadowStorage”
cmd= subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr = subprocess.PIPE,shell=True)
out=cmd.communicate()[0]
output = str(out)

def ecmd(command):
from subprocess import PIPE, Popen
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def enter(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def exit(self, type, value, traceback):
if self.success:
self._revert(self.old_value)

with disable_file_system_redirection():
    obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
out, err = obj.communicate()
ret=obj.returncode
if ret==0:
    if out:
        return out.strip()
    else:
        return ret
else:
    if err:
        return err.strip()
    else:
        return ret

def enable():
ps_content=r’’’

enable-computerrestore -drive "%s"
vssadmin resize shadowstorage /on=c: /for=c: /maxsize=%s
checkpoint-computer -description "Done"

'''%(drive,drive_percentage)
file_name='powershell_file.ps1'
file_path=os.path.join(os.environ['PROGRAMDATA'], file_name)
with open(file_path, 'wb') as wr:
    wr.write(ps_content)

ecmd('powershell "Set-ExecutionPolicy RemoteSigned"')
val=ecmd('powershell "%s"'%file_path)
if "WARNING:" in val:
    print "A new system restore point cannot be created because one has already been created within the past 24 hours. Please try again later..."
else:
    print "Restore point has been successfully enabled with percentage..."
os.remove(file_path)

def disable():
ps_content=r’’’

disable-computerrestore -drive "%s"

'''%drive
file_name_1='powershell_file.ps1'
file_path=os.path.join(os.environ['PROGRAMDATA'], file_name)
with open(file_path, 'wb') as wr:
    wr.write(ps_content)

ecmd('powershell "Set-ExecutionPolicy RemoteSigned"')
ecmd('powershell "%s"'%file_path)
os.remove(file_path)

if “No items found that satisfy the query.” in output:
print “Restore point not enabled in this machine”
enable()

elif “Shadow Copy Storage association” in output:
print “Restore point already enabled in this machine”
disable()
enable()

elif “Error: A Volume Shadow Copy Service component encountered an unexpected error.” in output:
print “Restore point already enabled in this machine”
disable()
enable()

elif “Error: You don’t have the correct permissions to run this command. Please run this utility from a command” in output:
print “Run this script as System User”

@matthew.hedtcke ,

We have reported the output of your test to our Script Developers. We will provide you with feedback from our Script Developers shortly.

Hi @matthew.hedtcke

Sorry for your inconvenience, we will modify the script and update you shortly.
Thank you

Hi @matthew.hedtcke

Please refer the below JSON file to achieve your need.
20180723-Enable-system-restore–and-set-percentage-drive.json

Thank you

20180723-Enable-system-restore–and-set-percentage-drive.json (4.48 KB)

Here is the error it is citing now.

Type of ticket creator: PROCEDURE
Event Created at: Mon Jul 23 14:54:19 2018 GMT+0
Device Name:
Logged on User: N/A
Data: Procedure wasn’t executed
There is no active logon session

I think that was because I didnt have it running by the system user. I made the change and haven’t seen that issue since.

@matthew.hedtcke ,

Indeed, the procedure needs be to utilized as System User. We thank you for your feedback.