Pruttelpot Posted August 4, 2008 Share Posted August 4, 2008 (edited) Gooday, I've got a problem; I used to write scripts in VBS, however, in the past I've also written scripts in AutoIT, And now I'm back to Auto it, but I cant get this working; Here it is: My VBS Script: expandcollapse popupSet objExcel = CreateObject("Excel.Application") objExcel.Visible = True objExcel.Workbooks.Add intRow = 2 Const ForReading = 1 objExcel.Cells(1, 1).Value = "Hostname" objExcel.Cells(1, 2).Value = "Totaal tijd op" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("Machines.txt", ForReading) Do While objTextFile.AtEndOfStream <> True strComputer = objtextFile.ReadLine Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_PerfOS_System") For Each objOS in colOperatingSystems Dim intSystemUptimeSec Dim intSystemUptimeMin Dim intSystemUptimeHour Dim intSystemUptimeDay intSystemUptimeDay = Int(objOS.SystemUpTime / 86400) intSystemUptimeHour = Int(objOS.SystemUpTime / 3600) - (intSystemUptimeDay*24) intSystemUptimeMin = Int(objOS.SystemUpTime / 60) - (intSystemUptimeHour*60) - (intSystemUptimeDay*24*60) intSystemUptimeSec = Int(objOS.SystemUpTime) - (intSystemUptimeMin*60) - (intSystemUptimeHour*60*60) - (intSystemUptimeDay*24*60*60) intSystemUptime = Int(objOS.SystemUpTime / 60) objExcel.Cells(intRow, 1).Value = strComputer objExcel.Cells(intRow, 2).Value = intSystemUptimeDay & "d " & intSystemUptimeHour & "h " & intSystemUptimeMin & "m " & intSystemUptimeSec & "s" If intSystemUptimeDay & "d " & intSystemUptimeHour & "h " & intSystemUptimeMin & "m " & intSystemUptimeSec & "s" => "1" Then objExcel.Cells(intRow, 2).Font.ColorIndex = 3 objExcel.Cells(intRow, 2).Font.Bold = True objExcel.Cells(intRow, 1).Font.Bold = True Else End If Next intRow = intRow + 1 set objWMIService = nothing set colOperatingSystems = nothing objExcel.Range("A1:B1").Select objExcel.Selection.Interior.ColorIndex = 19 objExcel.Cells.EntireColumn.AutoFit Loop What this does is read all the computer names, and gets the uptime thru WMI calls, and prints it to a excell sheet ()marks is bold and red when over 1 day, handy for our Terminal servers. But when I want to get this done in AU3, I can't get it to give me a days, hours, minutes, seconds output; expandcollapse popup#include <Date.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output &= "Computer: " & $strComputer & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $SystemUptime = ($objItem.SystemUpTime / 60) Dim $SystemUptimeDay Dim $SystemUptimeHour Dim $SystemUptimeMin Dim $SystemUptimeSec $SystemUptimeDay = ($objItem.SystemUpTime / 86400) $SystemUptimeHour = ($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24) $SystemUptimeMin = ($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60) $SystemUptimeSec = ($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60) Msgbox(0, "Uptime:", "Days : " & $SystemUptimeDay & "Uren" & $SystemUptimeHour & "Minuten" & $SystemUptimeMin & "Seconden " & $SystemUptimeSec) Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System" ) Endif Can anybody give me a hint on how to do this correctly? Thanks in advance. Edited August 4, 2008 by Pruttelpot Link to comment Share on other sites More sharing options...
Developers Jos Posted August 4, 2008 Developers Share Posted August 4, 2008 This version works for me: #include <Date.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output = "" $Output &= "Computer: " & $strComputer & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $SystemUptime = ($objItem.SystemUpTime / 60) Dim $SystemUptimeDay Dim $SystemUptimeHour Dim $SystemUptimeMin Dim $SystemUptimeSec $SystemUptimeDay = Int($objItem.SystemUpTime / 86400) $SystemUptimeHour = Int($objItem.SystemUpTime / 3600) - ($SystemUptimeDay * 24) $SystemUptimeMin = Int($objItem.SystemUpTime / 60) - ($SystemUptimeHour * 60) - ($SystemUptimeDay * 24 * 60) $SystemUptimeSec = Int($objItem.SystemUpTime) - ($SystemUptimeMin * 60) - ($SystemUptimeHour * 60 * 60) - ($SystemUptimeDay * 24 * 60 * 60) MsgBox(0, "Uptime:", "Days:" & $SystemUptimeDay & " Uren:" & $SystemUptimeHour & " Minuten:" & $SystemUptimeMin & " Seconden:" & $SystemUptimeSec) Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System") EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Pruttelpot Posted August 4, 2008 Author Share Posted August 4, 2008 This version works for me: <cut> Damn, So Int* should stay... Thank you verry much! 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