Returning uptime via HTA

Posted on 2009-04-15
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
    LVL 7

    Accepted Solution

    LVL 1

    Assisted Solution


    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    733 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

    23 Experts available now in Live!

    Get 1:1 Help Now