Solved

VBscript Uptime

Posted on 2010-08-13
5
1,094 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now