How to Enable System Restore Using a Script.

here’s a script that enables System Restore on a computer running Windows XP:

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\default”)

Set objItem = objWMIService.Get(“SystemRestore”)
errResults = objItem.Enable(“”)

The script itself starts out in typical fashion, connecting to the WMI service on the local computer. (Although, like all good WMI scripts, this one will also work against remote computers; just assign the name of that computer to the variable strComputer.) One thing to watch out for, however: unlike most WMI scripts this one doesn’t connect to the root\cimv2 namespace; instead, it connects to the root\default namespace. Why? That’s where all the System Restore WMI classes reside.

After making the connection use the Get method to bind to the SystemRestore class; that’s what we do here:

Set objItem = objWMIService.Get(“SystemRestore”)

At that point you can enable System Restore on all drives by simply calling the Enable method and passing an empty string (“”) as the sole parameter.

To enable System Restore on a particular drive; Here’s a script that enables System Restore only for drive D on the local computer:

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\default”)

Set objItem = objWMIService.Get(“SystemRestore”)
errResults = objItem.Enable(“D:\”)

The only difference to the first script lies with the parameter passed to the Enable method.
To enable System Restore on all drives pass an empty string to this method; to enable System Restore only on drive D pass the Enable method this parameter: D:\. In other words, the drive letter (D) followed by :\ is passed. To enable System Restore on drive E and drive E only use this line of code:

errResults = objItem.Enable(“E:\”)

Etc.

If you later want to disable System Restore on a computer; Here’s a script that disables System Restore for all the drives on a computer:

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\default”)

Set objItem = objWMIService.Get(“SystemRestore”)
errResults = objItem.Disable(“”)

The only difference to the first script is that this time the Disable method is called instead of the Enable method. System Restore can be disbaled for a specific drive too. Tired of running System Restore on drive D then:

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\default”)

Set objItem = objWMIService.Get(“SystemRestore”)
errResults = objItem.Disable(“D:\”)

Source…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: