Sleestack90
asked on
VBscript Uptime
I have the following script that displays uptime:
Set objWMIService=GetObject("w inmgmts:\\ .\root\cim v2")
Set colOperatingSystems=objWMI Service.Ex ecQuery _
("Select * From Win32_PerfFormattedData_Pe rfOS_Syste m")
For Each objOS in colOperatingSystems
intSystemUptime=Int(objOS. SystemUpTi me)
TimedAt=FormatDateTime(Dat e(),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).
Set objWMIService=GetObject("w
Set colOperatingSystems=objWMI
("Select * From Win32_PerfFormattedData_Pe
For Each objOS in colOperatingSystems
intSystemUptime=Int(objOS.
TimedAt=FormatDateTime(Dat
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).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not aware of bginfo, let me check if I can help
ASKER
This is what needs to be changed: wscript.echo to just echo
Set objWMIService=GetObject("w inmgmts:\\ .\root\cim v2")
Set colOperatingSystems=objWMI Service.Ex ecQuery _
("Select * From Win32_PerfFormattedData_Pe rfOS_Syste m")
For Each objOS in colOperatingSystems
intSystemUptime=Int(objOS. SystemUpTi me)
TimedAt=FormatDateTime(Dat e(),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
Set objWMIService=GetObject("w
Set colOperatingSystems=objWMI
("Select * From Win32_PerfFormattedData_Pe
For Each objOS in colOperatingSystems
intSystemUptime=Int(objOS.
TimedAt=FormatDateTime(Dat
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
ASKER
Put me on the right path
ASKER
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("w
Set colOperatingSystems=objWMI
("Select * From Win32_PerfFormattedData_Pe
For Each objOS in colOperatingSystems
intSystemUptime=Int(objOS.
TimedAt=FormatDateTime(Dat
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