Solved

VBscript Uptime

Posted on 2010-08-13
5
1,119 Views
Last Modified: 2012-05-10
I have the following script that displays uptime:

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


I would like to be able to call this inside a command prompt and have the result passed back into the command prompt instead of opening a message box (line 7).
0
Comment
Question by:Sleestack90
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
madhubabus earned 500 total points
ID: 33430673
change the message box to wscript.echo.

Now save the contents to a file say "ee.vbs"
from command prompt run
cscript  ee.vbs

this will write the output to console
0
 

Author Comment

by:Sleestack90
ID: 33430958
When I use this, it does output to the console, however when I call the script in BGinfo this is what it reutrns:

Error evaluating scripted field 'Uptime'
Microsoft VBSctipr runtime error
Line 7, position 2
Object required: 'wscrip'


This is what my script currently looks like:

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)
  wscript.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 MOD 24 &" Hours, " &M &" Minutes"
End Function
0
 
LVL 3

Expert Comment

by:madhubabus
ID: 33431009
I am not aware of bginfo, let me check if I can help
0
 

Author Comment

by:Sleestack90
ID: 33431774
This is what needs to be changed: wscript.echo to just echo

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)
   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 MOD 24 &" Hours, " &M &" Minutes"
End Function
0
 

Author Closing Comment

by:Sleestack90
ID: 33431916
Put me on the right path
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question