Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VBScript to find uptime for the list of server

VBScript to find uptime for the list of server

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("Server1","Server2","Server3","Server4","Server5","Server6")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "Caption: " & objItem.Caption
      WScript.Echo "LastBootUpTime: " & WMIDateStringToDate(objItem.LastBootUpTime)
      WScript.Echo "LocalDateTime: " & WMIDateStringToDate(objItem.LocalDateTime)
      WScript.Echo "Up Time: " & DateDiff("h", WMIDateStringToDate(objItem.LastBootUpTime), WMIDateStringToDate(objItem.LocalDateTime))
      WScript.Echo
   Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

How helpful was this article to you?

Related Articles

article VBScript to List Network Shares
This script will interrogate the operating...

(No rating)  5-1-2008    Views: 138   
article VBScript to List Network Shares with InputBox
Instructions for displaying a list of a...

(No rating)  5-1-2008    Views: 119   
article VBScript to Change Admin Password on a list of Computers
Create a text file listing one computer...

(No rating)  5-2-2008    Views: 141   

User Comments

Add Comment
No comments have been posted.