Rokkitt Posted May 13, 2013 Posted May 13, 2013 Hi, I am attempting to create a script that will query WMI for the "LastBootUpTime" of the local computer. It seems I am up against what I believe are Syntax errors, I have attempted to convert the code from VB Script but it does not help. Using snippets from the forum I have managed to get something together but there is no output no matter how I approach it. $objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & @ComputerName & 'rootcimv2:Win32_OperatingSystem') MsgBox(0, "Boot Time", "Last Reboot " & $objWMI.LastBootUpTime) The converted code: $strComputer = "." $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2") $colItems = $objWMIService.ExecQuery( _ "SELECT * FROM Win32_OperatingSystem WHERE LastBootUpTime = 20130513124052.319668+600",,48) The format I am attempting to output is: yyyy/mm/dd/hh/mm/ss although if I can just get some output I am sure I can work it out. Can anyone point me to anything to assist, I am quite new to AUTOIT and a complete novice extracting info from WMI. Thanks Just a little less hair after today..
Solution mikell Posted May 13, 2013 Solution Posted May 13, 2013 (edited) $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery( "SELECT LastBootUpTime FROM Win32_OperatingSystem") For $objItem In $colItems $LastBootUpTime = WMIDateStringToDate($objItem.LastBootUpTime) Next Msgbox(0,"", $LastBootUpTime) Func WMIDateStringToDate($dtmDate) ; yyyy/mm/dd/hh/mm/ss Return (StringLeft($dtmDate, 4) & "/" & StringMid($dtmDate, 7, 2) _ & "/" & StringMid($dtmDate, 5, 2) & "/" & StringMid($dtmDate, 9, 2) _ & "/" & StringMid($dtmDate, 11, 2) & "/" & StringMid($dtmDate,13, 2)) EndFunc For WMI things you should use scriptomatic.au3 Edited May 13, 2013 by mikell Rokkitt 1
spudw2k Posted May 14, 2013 Posted May 14, 2013 Yet more Boot (Up) Time examples for your viewing pleasure. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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