AutoHotkey Community

It is currently May 27th, 2012, 6:05 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: March 21st, 2007, 8:50 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
This used to be 1-line code in VBS-like COM invoking, which I'd written for someone else (:I don't use system restore). Now as there was a request of it again here, I tried to translate it into VTable way, and it became lots of codes. May consider using instead SRSetRestorePoint API.
Code:
COM_Init()
pobj := COM_GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:SystemRestore")
COM_Invoke(pobj, "CreateRestorePoint", "Install Application", 0, 100)
COM_Release(pobj)
COM_Term()


Last edited by Sean on December 4th, 2007, 6:17 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2007, 9:35 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
I can't get this script to work correctly.

I altered the following piece :

InputBox,astr,"Create RP","Please enter a RP description"
pDesc := SysAllocString(%astr%)

and whilst there is a system restore point recorded, it has no description next to the time field.
I'm told by the script hresult= 0

I'm using Xp Pro sp2 as Admin.
Can you help?

_________________
Stuart Halliday


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2007, 11:22 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
quatermass wrote:
InputBox,astr,"Create RP","Please enter a RP description"
pDesc := SysAllocString(%astr%)

Remove %%, like
Code:
pDesc := SysAllocString(astr)

BTW, this has a length limit of 64 (:including terminating null, I think).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2007, 12:54 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
OK, I added a return value code for more specific error detecting. Both will be zero on success, I think.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2007, 10:21 am 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
Thanks Sean, that did it.

Thanks for pointing out the 64 char limit.

This will make it much easier for my users to upgrade software as I'm always telling them to do a CHKDSK and a Restore point and then reboot first in case something cocks it up!

Now I can force upon them all 3! :-)

_________________
Stuart Halliday


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2007, 6:19 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
The script in the top message is updated. Now, it looks similar to a VBScript one.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2007, 1:09 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
Sean wrote:
The script in the top message is updated. Now, it looks similar to a VBScript one.


Is that self-contained or does it need a library of some sort?

_________________
Stuart Halliday


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2007, 2:56 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
quatermass wrote:
Is that self-contained or does it need a library of some sort?

It needs COM Standard Library.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 12:40 am 
Offline

Joined: February 16th, 2010, 4:01 am
Posts: 60
I ran the code in the first post but it threw an error. My COM/WMI std lib is loaded and works with other WMI calls. I am using COM_Init and term (copy/paste all of first post's code).

The error:
Quote:
The COM Object may not be a valid Dispatch Object!
First ensure that COM Library has been init....


Perhaps this code (from 2007) needs to be updated because of changes in the library?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 4:00 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
No, the code should work with any build of COM library. Check first about your system and your settings on System Restore.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 4:23 pm 
Offline

Joined: February 16th, 2010, 4:01 am
Posts: 60
Tried this on XPsp3 and on Win7. Both give me the same error:
Quote:
ERROR: 0x80041003
DESC: Access denied

ERROR2: Exception occurred. (0x800200009)


Shouldn't be a permissions issue but it reads like it might be. What do you think?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2010, 9:50 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
I use this handy script to do a 'set Restore Point' on XP SP3.
Used it for a good long time.


Code:
#NoEnv
#Include Library\CoHelper.ahk

CoInitialize()
InputBox,astr,Create Restore Point,Please enter a short Restore Point description`nFor example - 'About to install XYZ product'
if ErrorLevel
{
EXITApp
}

WinSet,AlwaysOnTop,ON,Create Restore


Splashtexton,350,50,Create Restore Point, Working...`nThis shouldn't take more than a minute.

Namespace := "root\default"
Class  := "SystemRestore"
Method := "CreateRestorePoint"
RpDesc := "Description"
RpType := "RestorePointType"
EvType := "EventType"

Ansi2Unicode(Method, wMethod)
Ansi2Unicode(RpDesc, wRpDesc)
Ansi2Unicode(RpType, wRpType)
Ansi2Unicode(EvType, wEvType)

pDesc := SysAllocString(astr)   ; Replace the text as liked

pcls := GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\" . Namespace . ":" . Class)

DllCall(VTable(pcls, 28), "Uint", pcls, "UintP", pset)               ; Methods_
DllCall(VTable(pset,  8), "Uint", pset, "str", wMethod, "int", 0, "UintP", pmth)   ; Item
DllCall(VTable(pmth,  9), "Uint", pmth, "UintP", pins)               ; InParameters
DllCall(VTable(pins, 27), "Uint", pins, "UintP", ppro)               ; Properties_

VarSetCapacity(var, 8 * 2, 0)
EncodeInteger(&var + 0, 8)
EncodeInteger(&var + 8, pDesc)
DllCall(VTable(ppro, 8), "Uint", ppro, "str", wRpDesc, "int", 0, "UintP", pitm)      ; Item
DllCall(VTable(pitm, 8), "Uint", pitm, "Uint", &var)               ; Value
Release(pitm)

EncodeInteger(&var + 0, 3)
EncodeInteger(&var + 8, 0)
DllCall(VTable(ppro, 8), "Uint", ppro, "str", wRpType, "int", 0, "UintP", pitm)      ; Item
DllCall(VTable(pitm, 8), "Uint", pitm, "Uint", &var)               ; Value
Release(pitm)

EncodeInteger(&var + 8, 100)
DllCall(VTable(ppro, 8), "Uint", ppro, "str", wEvType, "int", 0, "UintP", pitm)      ; Item
DllCall(VTable(pitm, 8), "Uint", pitm, "Uint", &var)               ; Value
Release(pitm)


hResult := DllCall(VTable(pcls, 19), "Uint", pcls, "str", wMethod, "Uint", pins, "int", 0, "Uint", 0, "UintP", pout)   ; ExecMethod_

Release(ppro)
Release(pout)
Release(pins)
Release(pmth)
Release(pset)
Release(pcls)

SysFreeString(pDesc)

CoUninitialize()

SplashTextOff
IFequal,hResult,0
{
Msgbox,,Create Restore Point,Your System Restore point has been created successfully.`nPress OK to finish.
} else
{
MsgBox,,Create Restore Point,PROBLEM: Restore was NOT successful: Result = %hResult%. Probably free disk space is too low or fragmented.
}



Can we assume you've switched on 'System Restore' via the System Properties and you are logged in as a Full Administrator?

_________________
Stuart Halliday


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2010, 4:18 pm 
Offline

Joined: February 16th, 2010, 4:01 am
Posts: 60
Never had luck with this in Win7 via AHK but this .vbs file works for me:

http://www.sevenforums.com/tutorials/49 ... rtcut.html

(Just the .vbs from option 2)

Then just call it from AHK:
SplitPath, A_AhkPath,, AHKdir
RunWait, `"%AHKDir%\Scripts\Instant_Restore_Point.vbs`"


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], Google [Bot], Google Feedfetcher, JamixZol, Yahoo [Bot] and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group