Laddy Posted October 28, 2010 Share Posted October 28, 2010 (edited) Hello everyoneSorry for my english, I speak a little bit.I try to make my first AutoIt script using wmi.I try to list the 5 most recent System Restore points. I think me being out in the translation VBS -> Autoit and unfortunately I hit a trouble on the line 22.Can you help ?thank a lot.LaddyIf $colItems.Count = 0 ThenError Script i don't understand why ??$dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") $objWMI = ObjGet("winmgmts:\\localhost\root\default") $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore", "WQL", 0x10 + 0x20) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $i = 0 If $colItems.Count = 0 Then MsgBox(0, "Aucun Point", "No restore point in system.") Else $i = $colItems.Count ;For Each $objItem In $colItems If IsObj($colItems) Then For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate MsgBox(0, "RP", "[" & $dtmCreationTime & "]" & $objItem.Description) EndIf $i = $i - 1 Next EndIf EndIf Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate Exit Edited October 28, 2010 by Laddy Link to comment Share on other sites More sharing options...
Juvigy Posted October 28, 2010 Share Posted October 28, 2010 $colItems is empty - it looks like $objWMI.ExecQuery("SELECT * FROM SystemRestore", "WQL", 0x10 + 0x20) did not return any items. Link to comment Share on other sites More sharing options...
Laddy Posted October 28, 2010 Author Share Posted October 28, 2010 (edited) Hi Juvigy I am not sure I understood. Sorry colItems.Count normally should not be empty. With my script visual basic script I have no problem. If colItems.Count is empty, I take it that restoring system must be off right? How to fix this problem? this is not mandatory? "WQL", 0x10 + 0x20 Edited October 28, 2010 by Laddy Link to comment Share on other sites More sharing options...
Laddy Posted October 28, 2010 Author Share Posted October 28, 2010 Ok it's ok now thank a lot for your reply Link to comment Share on other sites More sharing options...
Juvigy Posted October 28, 2010 Share Posted October 28, 2010 $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") $objWMI = ObjGet("winmgmts:\\localhost\root\default") $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") ConsoleWrite($colItems.Count&@CRLF) Value of 0 means that it is disabled Link to comment Share on other sites More sharing options...
GEOSoft Posted October 28, 2010 Share Posted October 28, 2010 Here is another way to do what you want. Of course you will have to add the code to convert the date etc. $RPSet = ObjGet("winmgmts:root/default") $sColl = $RPSet.InstancesOf ("SystemRestore") MsgBox(0, "TEST Count", $sColl.count) for $RP in $sColl MsgBox(0, "Result", "Dir: RP" & $RP.SequenceNumber & ", Name: " & $RP.Description & ", Type: ", $RP.RestorePointType & ", Time: " & $RP.CreationTime) next George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
UEZ Posted October 28, 2010 Share Posted October 28, 2010 I modified your code a litte bit: $ip = "localhost" $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") $objWMI = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\default") $i = $objWMI.ExecQuery("SELECT * FROM SystemRestore").Count If $i = 0 Then MsgBox(0, "Aucun Point", "No restore point in system.") Else $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore", "WQL") ;For Each $objItem In $colItems If IsObj($colItems) Then For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate MsgBox(0, "RP", "[" & $dtmCreationTime & "]" & $objItem.Description) EndIf $i = $i - 1 Next EndIf EndIf Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate Exit Please test whether it is working! Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 28, 2010 Share Posted October 28, 2010 $colItems is empty - it looks like $objWMI.ExecQuery("SELECT * FROM SystemRestore", "WQL", 0x10 + 0x20) did not return any items.I think UEZ is hinting at this already, but I'll state it plainly. The "0x10 + 0x20" flags are $wbemFlagReturnImmediately (0x10), and $wbemFlagForwardOnly (0x20). These flags are used to speed up the results and minimize the amount of resources used. One of the consequences of $wbemFlagForwardOnly in particular is that the .count is made invalid (not available). When you get a collection using that flag you have to run your For/In/Next loop and count the items for yourself. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now