Jump to content

maniG

Member
  • Posts

    3
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Pakistan

Posts posted by maniG

  1. 10 hours ago, Yzöwl said:

    To check if system protection is enabled, I would probably use the registry to determine if RPSessionInterval is greater than 0.

    In a batch file to enable system protection on the OS drive with a maximum 15% size I would try this As administrator:

    
    @ECHO OFF
    SET "rKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore"
    SET "rVal=RPSessionInterval"
    SET "dVal="
    FOR /F "EOL=H Tokens=2*" %%# IN ('REG Query "%rKey%" /V "%rVal%" 2^>NUL'
    ) DO SET/A "dVal=%%$"
    IF NOT DEFINED dVal (ECHO ERROR! & PAUSE & EXIT/B)
    IF %dVal% EQU 0 (
    	WMIC /NameSpace:\\root\default PATH SystemRestore CALL Enable %SystemDrive%)
    VSSADMIN Resize Shadowstorage /For=%SystemDrive% /On=%SystemDrive% /MaxSize=15%%

    This is untested, (I am not telling you to change scripting language, just showing you a method of detection of the state of the mechanism).

    That seems to be a good way to check. So far what I have done is my script will attempt to create a restore point and in case of error it will call a function that will enable protection and then again create a restore point or will exit in case of success. Thank you for your help. 

  2. On 6/16/2017 at 9:37 PM, gunsmokingman said:

    I am not sure what you want but using this reference  https://msdn.microsoft.com/en-us/library/windows/desktop/aa378858(v=vs.85).aspx

    I put together this script run it and see if it what you need.

    
    Dim d,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")
    On Error Resume Next 
      For Each objItem In colItem 
       d = objItem.Name & "\"
       If (oSR.Enable(d)) = 0 Then
        wscript.Echo "Success" & vbTab & d
       Else 
        wscript.Echo "Failed " & vbTab & d
       End If
      Next

    Hey thankyou for the answer. I have made changes to the code. Basically before we create a restore point, system restore must be enabled and I wanted to know a way to check if it is enabled or not.

  3. I am using the following code in my visual basic script to enable system protection in windows 10 and it works perfectly fine. I am looking for a visual basic code that checks if protection on particular drive is enabled or not?

    and Sets Max usage to 15%. 

    If Not WScript.Arguments.Named.Exists("elevate") Then
      CreateObject("Shell.Application").ShellExecute WScript.FullName _
        , WScript.ScriptFullName & " /elevate", "", "runas", 1
      WScript.Quit
    End If
    Dim oSR
    
    Set oSR = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")
    
    
      oSR.Enable("C:" & "\")

    If someone can highlight the version of windows this code is compatible for, that would be great. :)

×
×
  • Create New...