Returning uptime via HTA

Posted on 2009-04-15
Medium Priority
Last Modified: 2012-05-06
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.
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
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)"
    End If
     Wscript.Echo strComputer & "||" & "UNREACHABLE"
   End If 
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
  Ping = False
 End If
End Function

Open in new window

Question by:Simon336697

Accepted Solution

sj_hicks earned 1280 total points
ID: 24153610

Assisted Solution

josepvalls earned 720 total points
ID: 24154102

Download this HTA:
You have a text box where you can write your script and have the output sent to another text box.

You can edit the HTA so your code loads by default in the input textbox.
You can also get some examples on how to navigate for files in the same HTA.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

864 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