e
Tue May 31 19:07:17 CDT 2005
e <eholley@cox.net> wrote in
news:Xns9667C5C383E0eholleycoxnet@207.46.248.16:
> "Torgeir Bakken \(MVP\)" <Torgeir.Bakken-spam@hydro.com> wrote in
> news:ukyYlZSZFHA.4008@tk2msftngp13.phx.gbl:
>
>> Ed H wrote:
>>
>>> Upon further investigation, I am getting the erorr when the file is
>>> read. My (one I got from the net) does not actually create the
>>> script, a > redirect creates it. The problem appears when I try to
>>> read the file back in. Here is the full function;
>>> (snip)
>> Hi,
>>
>> Try this one:
>>
>>
> <SNIP>
> That worked great, thanks MUCH
>
> But of course, their are two more things I would like before I
> consider my Computer status script "happy".
> First, I use tables to display the status of the server,
> based on
> ping response grey=down black = up. Is their an easy way to
> automatically generate a 3 wide table, based on the number of servers?
> I was considering doing a for each loop, so ubound would generate the
> number.
> Second, when the page is gernated using the Div method I
> found (M$ I
> think) I had an OK box at the bottom, but could not figure out how to
> tie that in with my script. I was trying to figure out an off button.
>
> Much thanks again.
>
BTW, Here is the script, its short;
'******************************************************************
' Program : ComputerStatus.vbs
'
' Version : 0.01
'
' Changes: 0.01 Script in early beta
' 0.02 Added Table to clean output, commented OK Button
' 1.00 Working beta completed, pause may need to be
' lengthened for server load, but should be find
' considering single ping.
'
' Features: Need to fix Run so that it returns the result as the
' run itself.
'
' Thanks To : Mark Hauschild
' : Rick Henry
' : nntp://msnews.microsoft.com
' : -Torgeir Bakken (MVP) <Torgeir.Bakken-
spam@hydro.com>
' : -Michael Harris (MVP) <mikhar@mvps.org>
' : -|{evin <You@dont.need>
' : -Joe (Joe'Software - www.jsware.net)
' :
http://www.crimsoneditor.com
' :
http://cwashington.netreach.net/main/default.asp?
topic=news
' :
http://www.thekurt.net/NetworkUtilities.htm
' : -Torgeir Bakken (Torgeir.Bakken@hydro.com)
'
' Programmer : Edwin Holley
' Date : 28APR05
'
' Description: This script will do a single ping to a computer
' then capture the results sending them to IE, using color to
' indicate status.
'
'******************************************************************
Const NOTIFY_SUCCESS = False
Const NOTIFY_FAILURE = False
Const NOTIFY_ON_COMPLETION = True
Const RESUME_ON_ERROR = False
If RESUME_ON_ERROR Then
On Error Resume Next
End If
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set IE = CreateObject("InternetExplorer.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a path and filename to a file in My Documents
strMyDocPath = WshShell.SpecialFolders("MyDocuments")
strTempFile = strMyDocPath & "\DIVExample.html"
'Create a file
fso.CreateTextFile (strTempFile)
Set f1 = fso.GetFile(strTempFile)
Set ts = f1.OpenAsTextStream(2, True)
'Write a blank HTML page to the file with an empty DIV element, and then
close the file
ts.WriteLine("<HTML><HEAD><TITLE>Server Status</TITLE></HEAD>")
ts.WriteLine("<BODY SCROLL='NO'><CENTER><FONT FACE='arial black'> <HR
COLOR='BLACK'>")
ts.WriteLine("<DIV id='MakeMeAnObject'></DIV>")
ts.WriteLine("<HR COLOR='BLACK'></FONT></CENTER></BODY></HTML>")
'ts.WriteLine("<script language=""VBScript"">")
'ts.WriteLine("<!--")
'ts.WriteLine("Dim ready")
'ts.WriteLine("Public TheForm")
'ts.WriteLine("Sub Button1_OnClick")
'ts.WriteLine("ready = 1")
'ts.WriteLine("End Sub")
'ts.WriteLine("Sub window_onload()")
'ts.WriteLine("Set TheForm = Document.ValidForm")
'ts.WriteLine("TheForm.fName.Value="" ")
'ts.WriteLine("ready = 0")
'ts.WriteLine("End Sub")
'ts.WriteLine("Public Function CheckVal ()")
'ts.WriteLine("CheckVal = ready")
'ts.WriteLine("End function")
'ts.WriteLine("-->")
'ts.WriteLine("</script>")
'ts.WriteLine("<form name=""ValidForm"">")
'ts.WriteLine("<font color=""#FF0099"">")
'ts.WriteLine("<input type=""button"" name=""Button1"" value="" OK "">
<br>")
'ts.WriteLine("</p>")
'ts.WriteLine("</form>")
ts.Close
'Run IE and load the file we just created
SetupIE(strTempFile)
'Set the DIV element as an object
Set objDIV = IE.Document.All("MakeMeAnObject")
Reps = 3
Do
'Change the innerHTML of the DIV object
ComputerStatus "localhost", localhost
ComputerStatus "mitchville.com", mitchville
ComputerStatus "bummer", bummer
ComputerStatus "msn.com", msn
ComputerStatus "slashdot.org", slashdot
objDiv.InnerHTML = "<table border><tr><td>" & localhost & "</td>
<td>" & mitchville & "</td><td>" & bummer & "</td></tr><tr><td>" & msn &
"</td><td>" & slashdot & "</td></tr></table>"
WScript.Sleep 14000
Reps = Reps - 1
Loop While Reps > 0
'Close IE and delete the file
IE.Quit
f1.Delete
If NOTIFY_ON_COMPLETION Then
PlayWav "C:\WINDOWS\Media\tada.wav"
End If
'End Script
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>
Sub SetupIE(File2Load)
IE.Navigate File2Load
IE.ToolBar = False
IE.StatusBar = False
IE.Resizable = True
Do
Loop While IE.Busy
IE.Width = 500
IE.Height = 400
IE.Left = 350
IE.Top = 0
IE.Visible = True
WshShell.AppActivate("Microsoft Internet Explorer")
End Sub
function ComputerStatus(strComputer, Result)
Info=Run("ping " & strComputer & " -n 1")
if instr(Info,"Reply from") = 0 then
Result = "<font color=""#C0C0C0""><strong>" & strComputer &
"</strong></font>"
If NOTIFY_FAILURE Then
PlayWav "C:\WINDOWS\Media\chord.wav"
End If
else
Result = "<strong>" & strComputer & "</strong>"
If NOTIFY_SUCCESS Then
PlayWav "C:\WINDOWS\Media\ding.wav"
End If
end if
end function
Function Run(sCmd)
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
oShell.Run "%comspec% /c " & sCmd & " >" & sTempFile & " 2>&1", 0, True
If oFSO.GetFile(sTempFile).Size > 0 Then
Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
Run = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
Else
Run = ""
End If
End Function
Function DorkBox(Text)
Title = "DorkBox - Remove after T/S"
MsgBox Text, vbInformation + vbOKOnly, Title
End Function
Sub PlayWav(sWaveFile)
Set oShell = CreateObject("Wscript.Shell")
oShell.Run "sndrec32 /play /close """ & sWaveFile & """",0,True
End Sub