Simon336697
asked on
Returning uptime via HTA
Hi guys,
I have the following vbscript that id like to convert to a hta.
It points to a text file which is currently hard coded into the script.
What id like to do is:
1) Convert this to a hta
2) Instead of hardcoding the text file path, have a browse button on the hta which gives you the option of pointing to a file to read instead.
3) Have the output of running the hta in the hta itself.
Any help greatly appreciated.
I have the following vbscript that id like to convert to a hta.
It points to a text file which is currently hard coded into the script.
What id like to do is:
1) Convert this to a hta
2) Instead of hardcoding the text file path, have a browse button on the hta which gives you the option of pointing to a file to read instead.
3) Have the output of running the hta in the hta itself.
Any help greatly appreciated.
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("d:\comps.txt", ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
StrComputer = objDictionary.Item(objItem)
If Ping(strComputer) = True Then
On Error Resume Next
set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
If Err.Number = 0 Then
for each objOS in colOS
objWMIDateTime.Value = objOS.LastBootUpTime
Wscript.Echo "System Up Time: " & TimeSpan(objWMIDateTime.GetVarDate,Now) & " (hh:mm:ss)"
next
End If
Else
Wscript.Echo strComputer & "||" & "UNREACHABLE"
End If
Next
Function TimeSpan(dt1, dt2)
' Function to display the difference between
' 2 dates in hh:mm:ss format
If (isDate(dt1) And IsDate(dt2)) = false Then
TimeSpan = "00:00:00"
Exit Function
End If
seconds = Abs(DateDiff("S", dt1, dt2))
minutes = seconds \ 60
hours = minutes \ 60
minutes = minutes mod 60
seconds = seconds mod 60
if len(hours) = 1 then hours = "0" & hours
TimeSpan = hours & ":" & _
RIGHT("00" & minutes, 2) & ":" & _
RIGHT("00" & seconds, 2)
End Function
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.