Help with styling HTA script

I've finally written my first fully functional HTA script.  There's just one more thing I need help figuring out.  My script monitors a couple of specific services on my local computer and enters the name of the services and the status of each into a HTML table.  I have set it up to run completely in auto to restart services if they're not running, or I can Stop Auto to start or stop the services as I want.  What I need help with, is figuring out how to change just the color of the status of the service in the output table to red if it's in any other state but "Running".  It's not a big deal, simply for aesthetic value, but any help would be greatly appreciated!


<head>
<title>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSnail Farmer's Server Status</title>
<HTA:APPLICATION 
    APPLICATIONNAME="Server Services"
    BORDER="thin"
    SCROLL="no"
    MinimizeButton="no"
    MaximizeButton="no"
    Sysmenu="no"
    SINGLEINSTANCE="yes"
    ID="oHTA"
>
<APPLICATION:HTA>
</head>

<style>
body {
    background-color: black;
    color: palegoldenrod;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 25px;
}
table {
    width: 100%;
    border-color: green;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 12px;
}
th {
    border-color: green;
    background-color: black;
    color: palegoldenrod;
}
td {
    border-color: green;
}

</style>

<script language="VBScript">

Dim Time, iTimerID


Sub Resize()
    Window.ResizeTo 385,200
End Sub

 
Sub Window_OnLoad
    ' Populate table with list of services
    Window.ResizeTo 385,200
	Timer()
End Sub


Sub Timer()
	If Time = "Stop" Then
		ListServicesB()
		iTimerID = window.setInterval("ListServicesB()", 15000)
	Else 
		ListServices()
		iTimerID = window.setInterval("ListServices()", 15000)
	End If
End Sub

 
Sub ListServices()
	sComputer = "."
    Set oTable = Document.All("list_servicenames")

    ' Delete any existing data rows
    rowCount = oTable.Rows.Length
    If rowCount > 1 Then
        For i = rowCount - 1 To 1 Step -1
            oTable.DeleteRow(i)
        Next
    End If

    ON ERROR RESUME NEXT

    ' Get all services from WMI
    set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_Service Where DisplayName = 'Spaced Out' Or DisplayName = 'Performance Issues' or DisplayName = '7 Days To Die'")

    ' For each services add a data row to the table
    For Each objItem in colItems
			Set TR = oTable.InsertRow()
			Set TD = TR.InsertCell()
			TD.InnerHTML = "<input type=""checkbox""></td>"
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.Name
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.State
    Next
	Restart()
End Sub


Sub Restart()

    sComputer = "."  

    ' Get all services from WMI
    set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery("Select * From Win32_Service Where DisplayName = 'Spaced Out' Or DisplayName = 'Performance Issues' or DisplayName = '7 Days To Die'")
		For Each objService in colServiceList
			If objService.State <> "Running" Then
				objService.StartService()
			End If
		Next
			If errReturn <> 0 Then
                MsgBox "Action = Start" & vbCrLf & "Service = " & strService & vbCrLf & "Error = " & errReturn, 0, "Error occured"
            End If
End Sub


Sub ListServicesB()
	sComputer = "."
    Set oTable = Document.All("list_servicenames")

    ' Delete any existing data rows
    rowCount = oTable.Rows.Length
    If rowCount > 1 Then
        For i = rowCount - 1 To 1 Step -1
            oTable.DeleteRow(i)
        Next
    End If

    ON ERROR RESUME NEXT

    ' Get all services from WMI
    set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_Service Where DisplayName = 'Spaced Out' Or DisplayName = 'Performance Issues' or DisplayName = '7 Days To Die'")

    ' For each services add a data row to the table
    For Each objItem in colItems
			Set TR = oTable.InsertRow()
			Set TD = TR.InsertCell()
			TD.InnerHTML = "<input type=""checkbox""></td>"
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.Name
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.State
		Next
End Sub


Sub btn_start_onClick()

    strComputer = "."                                                                                                   
    Set oTable = Document.All("list_servicenames")
    rowCount = oTable.Rows.Length

    ' Process all selected rows of table, Start service
    For i = 1 To rowCount - 1 Step 1
        If UCase(Left(oTable.Rows(i).Cells(0).InnerHTML, 14)) = "<INPUT CHECKED" Then
            strService = oTable.Rows(i).Cells(1).InnerHTML
            Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
            Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
            For each objService in colServiceList                                                                       
                errReturn = objService.StartService()                                                                   
            Next
            If errReturn <> 0 Then
                MsgBox "Action = Start" & vbCrLf & "Service = " & strService & vbCrLf & "Error = " & errReturn, 0, "Error occured"
            End If
        End If                                                                                                          
    Next                                                                                                                
	Timer()
End Sub

 
Sub btn_stop_onClick()

    strComputer = "."                                                                                                   
    Set oTable = Document.All("list_servicenames")
    rowCount = oTable.Rows.Length

    ' Process all selected rows of table, Stop service
    For i = 1 To rowCount - 1 Step 1
        If UCase(Left(oTable.Rows(i).Cells(0).InnerHTML, 14)) = "<INPUT CHECKED" Then
            strService = oTable.Rows(i).Cells(1).InnerHTML
            Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
            Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
            For each objService in colServiceList
                errReturn = objService.StopService()                                                                    
            Next                                                                                                        
            If errReturn <> 0 Then
                MsgBox "Action = Stop" & vbCrLf & "Service = " & strService & vbCrLf & "Error = " & errReturn, 0, "Error occured"
            End If
		End If
    Next                                                                                                                
	Timer()
End Sub


Sub btn_loop_onClick()
	Time = "Start"
	window.clearInterval(iTimerID)
	MsgBox "Auto Started!"
	ListServices()
End Sub


Sub btn_sloop_onClick()
    Time = "Stop"
	window.clearInterval(iTimerID)
	MsgBox "Auto Stopped!"
	ListServicesB()
End Sub                                                                                                              

 
Sub btn_Refresh_onClick()
    If Time = "Stop" Then
		ListServicesB()
	Else
		ListServices()
	End If
End Sub

 
Sub btn_exit_onClick()
    Window.Close
End Sub

</script>
 
<body>

<table border=1 style="margin-bottom:5px" id=list_servicenames> 
<col align="center">
<col align="left">
<col align="center">
<tr> 
<th align="center">Select</td>
<th align="center">Name</td>
<th align="center">State</td>
</tr> 
</table> 
 
<input type="button" value="Refresh"   name="btn_Refresh" id="btn_Refresh" title="Click to refresh the services list">
<input type="button" value="Start"     name="btn_start"   id="btn_start"   title="Click to Start the Services">
<input type="button" value="Stop"      name="btn_stop"    id="btn_stop"    title="Click to Stop the Service">
<input type="button" value="Auto"      name="btn_loop"    id="btn_loop"    title="Click to Start Timed Loop">
<input type="button" value="Stop Auto" name="btn_sloop"   id="btn_sloop"   title="Click to Stop Timed Loop">
<input type="button" value="Exit"      name="btn_exit"    id="btn_exit"    title="Click to Exit Form ">
 
</body>

Open in new window

Dennis DAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BRMarketingCommented:
I would solve it like this

First i would write a css style like this inside Style code

.running {
Background-color: #ff0;
Color: #f0f;

}
.notrunning {
Background-color: #f40;
Color: #f3f;

}


Then i would create a div where i show the ouput

If condtion is true, div class=" running " else  div class="notrunning"
0
Bill PrewIT / Software Engineering ConsultantCommented:
Here's an easy way to do it:

    ' For each services add a data row to the table
    For Each objItem in colItems
			Set TR = oTable.InsertRow()
			Set TD = TR.InsertCell()
			TD.InnerHTML = "<input type=""checkbox""></td>"
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.Name
			Set TD = TR.InsertCell()
			TD.InnerHTML = objItem.State
			If objItem.State = "Stopped" Then TD.style.color = "red"
    Next

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dennis DAuthor Commented:
That is exactly what I wanted it to do!  And you're right, that was easy! Thank you very much again, Bill!!!!
0
Bill PrewIT / Software Engineering ConsultantCommented:
You're welcome Dennis.


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.