Jump to content

vb script for Turn off the System Protection on all drives in Windows


Recommended Posts

Is possible to disable the system restore on all drives in Windows 7 using vb scripting ?

The only solution I have right now is a reg file obtained by using RegShot, but I guess it's not work on other computers:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SPP\Clients]
"{09F7EDC5-294E-4180-AF6A-FB0E6A0E9513}"=-
"{3E7F07C9-6BC3-11DC-A033-0019B92BB8B1}"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore]
"RPSessionInterval"=dword:00000000

Edited by radix
Link to comment
Share on other sites


The following is what I used to use on XP systems.

strComputer = "."
Set objWMISvc = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")

Set objItem = objWMISvc.Get("SystemRestore")
errResults = objItem.Disable("")

Disabling the service essentially prevents the System Restore on all drives.

Changing the last word to Enable would obviusly reverse the action.

Here's one which will cover both scenarios

'Enable or Disable System Restore

strComputer = InputBox("Enter the COMPUTER NAME or the IP ADDRESS of the " _
& "system on which you would like to Enable or Disable System Restore. " _
& vbCRLF & "(use localhost for current system)", "Remotely Enable or " _
& "Disable System Restore","localhost")

If strComputer = "" Then
WScript.Quit
End If

strChoice = Inputbox ("System Restore:" & vbCrLf & vbCrLf & "1: Enable" _
& vbCrLf & "2: Disable" & vbCrLf & vbCrLf & vbCrLf & "Please enter 1 or 2 " _
& "(leave blank to quit):", "Enter 1 to Enable or 2 to Disable","")

If strChoice = "" Then
WScript.Quit
End If

If strChoice = 1 Then
Set objWMISvc = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMISvc.Get("SystemRestore")
errResults = objItem.Enable("")
Mybox = MsgBox("System Restore is now enabled on " & strComputer & "" _
& vbCRLF ,vbOkOnly,"System Restore Enabled")
End If

If strChoice = 2 Then
Set objWMISvc = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMISvc.Get("SystemRestore")
errResults = objItem.Disable("")
Mybox = MsgBox("System Restore is now disabled on " & strComputer & "" _
& vbCRLF ,vbOkOnly,"System Restore Disabled")
End If

Link to comment
Share on other sites

There's a good reason why it doesn't work anymore: the system restore service doesn't exist on Win7 (setting a non-existent service to disabled accomplishes nothing). There's no straight replacement for it so you can't just disable a service anymore.

The easiest thing to do now is to use the Disable-ComputerRestore in PowerShell e.g.

Disable-ComputerRestore "C:\", "D:\"

But you can still do it in VBScript using the relevant WMI classes if that's what you prefer, or even using WMI in PowerShell:

([wmiclass]"\\.\root\default:systemrestore").Disable("C:\")

Link to comment
Share on other sites

I believe that with the Disable method of the WMI SystemRestore class an empty string, (""), can be used as a parameter if you wish to disable System Restore for all drives.

Alternatively, try this.

Link to comment
Share on other sites

with the Disable method of the WMI SystemRestore class an empty string, (""), can be used as a parameter if you wish to disable System Restore for all drives

According to the documentation it should work (just like it would also work for my WMI example above):

Parameters

Drive [in]

The drive to be disabled. The drive string should be of the form "C:\". If this parameter is the system drive or an empty string (""), no drives are monitored.

Not that I tested any of it (I'm too lazy to enable it on multiple drives just to test disabling it)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...