I'm programmatically trying to enable/disable System Restore in Windows 7. I have enable system restore working "Enable-ComputerRestore", but disable is giving me issues.
Disable-ComputerRestore -drive "C:\"
doesn't set my C: drive to "Turn off system protection". It sets it to "Only restore previous versions of files" instead. Anyone have a clue as to why this could be happening?
You just have to do it localy (no remote) as administrator :
The command
Be careful, you have to close the system properties windo and reopen it to see the result.
I'm solving this using WMI and the following C# code adapted from here .
public void disableSystemRestore(string drive)
{
try
{
ManagementScope scope = new ManagementScope("\\\\localhost\\root\\default");
ManagementPath path = new ManagementPath("SystemRestore");
ObjectGetOptions options = new ObjectGetOptions();
ManagementClass process = new ManagementClass(scope, path, options);
ManagementBaseObject inParams = process.GetMethodParameters("Disable");
inParams["Drive"] = drive;
ManagementBaseObject outParams = process.InvokeMethod("Disable", inParams, null);
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.