[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4005
  • Last Modified:

Uptime VB Script for BGInfo

Hi,

I have the following script to show the server's uptime on the desktop using BGInfo (http://www.sysinternals.com/Utilities/BgInfo.html):

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * From Win32_PerfFormattedData_PerfOS_System")
 
For Each objOS in colOperatingSystems
    intSystemUptime = Int(objOS.SystemUpTime / 60)
    Echo intSystemUptime & " minutes"
Next
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

However this outputs the uptime only in minutes. Please can it be improved to show the uptime in the following format:

For example: 1 Days, 1 Hours, 4 Minutes, 52 Seconds?

Thanks
0
simonprr
Asked:
simonprr
  • 3
  • 3
1 Solution
 
bruintjeCommented:
Hello simonprr,

you could look at the script posted here
source: http://board.msfn.org/lofiversion/index.php/t73147.html
----------
Set objWMIService=GetObject("winmgmts:\\" &strComputer &"\root\cimv2")
Set colOperatingSystems=objWMIService.ExecQuery _
  ("Select * From Win32_PerfFormattedData_PerfOS_System")
For Each objOS in colOperatingSystems
  intSystemUptime=Int(objOS.SystemUpTime)
  TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4)
  Echo UpTime(intSystemUptime)
Next
Function UpTime(S)
  M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24
  UpTime=D &" Days, " &H &" Hours, " &M &" Minutes"
End Function
----------

hope this helps a bit
bruintje
0
 
simonprrAuthor Commented:
Thanks, but I get the following error:

Error evaluating scripted field 'Uptime2'
(null)
Line 1, position 0
(null)
0
 
bruintjeCommented:
sorry had to replace the strcomputer for .

Set objWMIService=GetObject("winmgmts:\\.\root\cimv2")
Set colOperatingSystems=objWMIService.ExecQuery _
  ("Select * From Win32_PerfFormattedData_PerfOS_System")
For Each objOS in colOperatingSystems
  intSystemUptime=Int(objOS.SystemUpTime)
  TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4)
  Msgbox UpTime(intSystemUptime)
Next
Function UpTime(S)
  M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24
  UpTime=D &" Days, " &H &" Hours, " &M &" Minutes"
End Function

maybe you need to change the Msgbox for Echo but it worked for me :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
simonprrAuthor Commented:
Yes works now, but it says:

1 Days, 47 Hours, 4 Minutes

The real uptime is:

1 Days, 23 Hours, 4 Minutes

So for some reason it's not calculating the hours based on the number of days....
0
 
bruintjeCommented:
:-) missed that too, hmmm shouldn't trust anything on the web

this will MOD the days from the hours

Set objWMIService=GetObject("winmgmts:\\.\root\cimv2")
Set colOperatingSystems=objWMIService.ExecQuery _
  ("Select * From Win32_PerfFormattedData_PerfOS_System")
For Each objOS in colOperatingSystems
  intSystemUptime=Int(objOS.SystemUpTime)
  TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4)
  Msgbox UpTime(intSystemUptime)
Next
Function UpTime(S)
  M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24
  UpTime=D &" Days, " & H MOD 24 &" Hours, " &M &" Minutes"
End Function
0
 
simonprrAuthor Commented:
Thanks, works great.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now