[SOLVED]Silent restore point

Discussion in 'Mixed Languages' started by QuantumBug, Aug 7, 2012.

  1. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #1 QuantumBug, Aug 7, 2012
    Last edited: Aug 8, 2012
    Thought I'd post in here as technically it's a programming help question.

    Is there any way to create a silent system restore point with any kind of command line? Is being implimented into Protweak. I can't find anything decent online so I have checked.

    Operating Systems in question are Windows Vista, 7 and 8.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #2 stevemk14ebr, Aug 7, 2012
    Last edited by a moderator: Apr 20, 2017
    adapted from http://www.freevbcode.com/ShowCode.asp?ID=6911

    Code:
     Public Class Form1
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Call ListPoints()
            Dim obj As Object
            obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")
    
            'The date and ID are auto added
            Call obj.CreateRestorePoint("Give it a name", 12, 100)
    
        End Sub
       
    
     Public Sub ListPoints() 'Adds all Restore Points to a ListView
    
            Dim o As Object
            Dim sr As Object
            Dim num As Byte
    
            'Get all points and add them to "o"
            o = GetObject("winmgmts:root/default").InstancesOf("SystemRestore")
    
            'Scroll through "o"
            For Each sr In o
                num += 1
                'Adds a point to a ListView then shows num of restore not that after 
                'creating the restore it will not show a nother restore until restarting app
                ListView2.Items.Add(sr)
                MessageBox.Show(num)
    
    
    
            Next sr
    
        End Sub
    End Class
    P.S is it time for me to join you in coding or are u finalizing stuff before u send it, or am i no longer working on it
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #3 QuantumBug, Aug 7, 2012
    Last edited: Aug 7, 2012
    (OP)
    Awesome, will check it out.

    Sorry about being slow with the ProTweak development. I've started moving each tweak into Public Functions to be called whenever, instead of the code being integrated into every button click and a lot needs commenting.

    EDIT: Steve am finalizing stuff before it's sent :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #4 stevemk14ebr, Aug 7, 2012
    Last edited by a moderator: Apr 20, 2017
    ok good to hear and btw u only need this sub to make the restore
    Code:
     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Call ListPoints()
            Dim obj As Object
            obj = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:SystemRestore")
    
            'The date and ID are auto added
            Call obj.CreateRestorePoint("Give it a name", 12, 100)
    
        End Sub
    the other sub is just to keep tabs how many restore points u hav, didn't know if u caught that
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #5 QuantumBug, Aug 7, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Yeah I got it :) You can remove the red...
    Code:
    Call ListPoints()
    
    May come in handy for ProTweak though.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,864
    20,048
    180
    #6 Alphawaves, Aug 7, 2012
    Last edited by a moderator: Apr 20, 2017
    I think if its just for a tweaks option then something simple..

    Code:
    Dim ogo As New ObjectGetOptions()
    Dim mclass As New ManagementClass("\\localhost\root\default", "SystemRestore", ogo)
    Dim obj As ManagementBaseObject = mclass.GetMethodParameters("CreateRestorePoint")
    obj("Description") = "My restore name"
    obj("RestorePointType") = 0
    obj("EventType") = 100
    Dim OutParams As ManagementBaseObject = mclass.InvokeMethod("CreateRestorePoint", obj, Nothing)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #7 QuantumBug, Aug 7, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks, Alpha :)

    Is not a tweak, it's a precation in the home screen to create a restore before using tweaks.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #8 stevemk14ebr, Aug 8, 2012
    Last edited: Aug 8, 2012
    there is one advantage to my original code- you don't need to referance any dll's :/

    EDIT-alpha i was fooling around with the same exact code as that (before i posted the one above) but i couldn't declare any of the managment stuff, turns out i forgot to referance the dll lol
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    There's no reference to any dll, just Windows Management Instruction :)

    WMI is actually very handy, but slow if not referenced well.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #10 QuantumBug, Aug 8, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    you need to add a reference for System.Management then import it in the application.

    Top menu > Project > Add reference > .NET > System.Managament...

    Next step is to use this code in your application

    Code:
    Imports System.Management
    
    EDIT: Sorry I see you've already done it lmao. I'm blind =/
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...