Jump to content
Sign in to follow this  
Rokkitt

Help with WMI query

Recommended Posts

Rokkitt

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..;)

 

Share this post


Link to post
Share on other sites
mikell

$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 by mikell
  • Like 1

Share this post


Link to post
Share on other sites
Rokkitt

Your a legend, thanks Mikell....;)

Share this post


Link to post
Share on other sites
spudw2k

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×