Jump to content

wmic to disable system restore


Recommended Posts

How to disable system restore on all drives using wmic?

This command works for the specified drive. wmic /namespace:\\root\default path SystemRestore call Disable %SystemDrive%\

Also I can use wmic to list drive letter usig wmic logicaldisk get caption. But I don't know how to combine these two commands. Anyone can help?

thank you.

Link to comment
Share on other sites


Ok then. WMIC merely makes calls to WMI methods, so here's a quick and dirty vbscript that makes the same query and calls the exact same method:


Option Explicit
Dim oWMI, oSR, colItem, objItem
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set oSR = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")
Set colItem = oWMI.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3")
For Each objItem in colItem
oSR.Disable(objItem.DeviceID & "\")
Next

Very little testing of any kind has been done (only 1 VM, with 1 drive, once) but it seems to work fine (even the restore points got deleted)

Edit: the board seems to screw up the code formatting, especially with code tags (still messed up with quote tags or none at all). Watch for the parenthesis after cimv2... It should be on the same line, and if you see a space there, then it's the board that insists on adding it for no good reason. If you hit the "reply" button, you'll seemingly be able to copy/paste the code in its un-crippled format from there. Sorry about that, there's nothing I can do to make IPB work as you'd expect it to.

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...