 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Mar 21, 2007 7:50 am Post subject: Create System Restore Point via WMI |
|
|
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 Tue Dec 04, 2007 5:17 am; edited 3 times in total |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 216
|
Posted: Wed Mar 21, 2007 8:35 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Mar 21, 2007 10:22 pm Post subject: |
|
|
| 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). |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Mar 21, 2007 11:54 pm Post subject: |
|
|
| OK, I added a return value code for more specific error detecting. Both will be zero on success, I think. |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 216
|
Posted: Thu Mar 22, 2007 9:21 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Dec 04, 2007 5:19 am Post subject: |
|
|
| The script in the top message is updated. Now, it looks similar to a VBScript one. |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 216
|
Posted: Tue Dec 04, 2007 12:09 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Dec 04, 2007 1:56 pm Post subject: |
|
|
| quatermass wrote: | | Is that self-contained or does it need a library of some sort? |
It needs COM Standard Library. |
|
| Back to top |
|
 |
tain
Joined: 16 Feb 2010 Posts: 55
|
Posted: Sat Mar 13, 2010 11:40 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Sun Mar 14, 2010 3:00 am Post subject: |
|
|
| No, the code should work with any build of COM library. Check first about your system and your settings on System Restore. |
|
| Back to top |
|
 |
tain
Joined: 16 Feb 2010 Posts: 55
|
Posted: Sun Mar 21, 2010 3:23 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 216
|
Posted: Mon Mar 22, 2010 8:50 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
tain
Joined: 16 Feb 2010 Posts: 55
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|