VBS Script To Send A Remote Machines Service Information To A Web Page

 

This VBS script will allow you to enter a remote machine name into an input dialog box and will in turn list the services on that machine with their current state marked Green (Running) or Red (Stopped) as appropriate to a web page.

 

VBS Script:

 

strComputer = InputBox ("Enter Machine Name")

 

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")

objExplorer.Navigate "About:Blank"

objExplorer.Document.Title = "Created By Don Hite For myITforum.Com"

objExplorer.ToolBar = 0

objExplorer.StatusBar = 0

objExplorer.Visible = 1

 

strHTML = "<table border='1' style='border-collapse: collapse' bordercolor='SaddleBrown' id='Table1' >"

strHTML = strHTML & "<tr>"

strHTML = strHTML & "<td width='10%' bgcolor = 'SeaShell'><font color = 'Blue'><b>Name</td>"

strHTML = strHTML & "<td width='10%' bgcolor = 'SeaShell'><font color = 'Blue'><b>Display Name</td>"

strHTML = strHTML & "<td width='10%' bgcolor = 'SeaShell'><font color = 'Blue'><b>Start Mode</td>"

strHTML = strHTML & "<td width='10%' bgcolor = 'SeaShell'><font color = 'Blue'><b>State</td>"

strHTML = strHTML & "</tr>"

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * From Win32_Service")

For Each objItem in colItems

 

strHTML = strHTML & "<tr>"

strHTML = strHTML & "<td width='10%'>" & objItem.Name & "</td>"

strHTML = strHTML & "<td width='10%'>" & objItem.DisplayName  & "</td>"

strHTML = strHTML & "<td width='10%'>" & objItem.StartMode & "</td>"

If objItem.State = "Running" Then

strHTML = strHTML & "<td width='10%'><Font Color='Green'>" & objItem.State & "</Font></td>"

ElseIf objItem.State = "Stopped" Then

strHTML = strHTML & "<td width='10%'><Font Color='Red'>" & objItem.State & "</Font></td>"

End If

Next

 

strHTML = strHTML & "</tr>"

strHTML = strHTML & "</table>"

strHTML = strHTML & "</tr>"

strHTML = strHTML & "<p align='center'> <font color='Blue'>Please Visit myITforum.Com</p>"

strHTML = strHTML & "</tr>"

 

objExplorer.Document.Body.BgColor = "CornSilk"

objExplorer.Document.FgColor = "SaddleBrown"

objExplorer.Document.Body.InnerHTML = strHTML

 

 

Published Sunday, October 19, 2008 1:14 PM by dhite
Filed under:

Comments

No Comments