I have a Function to create a temp file to then, pipe to, to collect the
response. It seems broke, under XP for some reason. I get the error when
the file is created, so I am thinking that the error is in the code below;

Dim fso, fldTemp, sTempName, filTemp

Const TemporaryFolder = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(TemporaryFolder)
filTemp = fso.GetTempName
sTempName = fldTemp.Path & "\" & filTemp

This script will run on WIN2K, when it is done :-)

Re: Hellp with temp file by Steven

Steven
Mon May 30 08:39:21 CDT 2005

Try;

Const TemporaryFolder =3D 2
Set fso =3D CreateObject("Scripting.FileSystemObject")
Set fldTemp =3D fso.GetSpecialFolder(TemporaryFolder)
On Error Resume Next
filTemp =3D fso.GetTempName
sTempName =3D fldTemp.Path & "\" & filTemp
If Err.Number <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Else
MsgBox sTempName & " created!"
End If


--=20
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"e" <eholley@cox.net> wrote in message =
news:Xns96665F5B7357Deholleycoxnet@207.46.248.16...
> I have a Function to create a temp file to then, pipe to, to collect =
the=20
> response. It seems broke, under XP for some reason. I get the error =
when=20
> the file is created, so I am thinking that the error is in the code =
below;
>=20
> Dim fso, fldTemp, sTempName, filTemp
>=20
> Const TemporaryFolder =3D 2
> Set fso =3D CreateObject("Scripting.FileSystemObject")
> Set fldTemp =3D fso.GetSpecialFolder(TemporaryFolder)
> filTemp =3D fso.GetTempName
> sTempName =3D fldTemp.Path & "\" & filTemp
>=20
> This script will run on WIN2K, when it is done :-)


Re: Hellp with temp file by Torgeir

Torgeir
Mon May 30 08:42:42 CDT 2005

e wrote:

> I have a Function to create a temp file to then, pipe to, to collect the
> response. It seems broke, under XP for some reason. I get the error when
> the file is created, so I am thinking that the error is in the code below;
>
> Dim fso, fldTemp, sTempName, filTemp
>
> Const TemporaryFolder = 2
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set fldTemp = fso.GetSpecialFolder(TemporaryFolder)
> filTemp = fso.GetTempName
> sTempName = fldTemp.Path & "\" & filTemp
>
> This script will run on WIN2K, when it is done :-)
Hi,

The script above works fine foe me on WinXP.


I use this code to obtain a temp file in the temp folder, this
way I avoid any space problems later on:

Set fso = CreateObject("Scripting.FileSystemObject")
sTempName = fso.GetSpecialFolder(2).ShortPath & "\" & fso.GetTempName



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Hellp with temp file by Ed

Ed
Mon May 30 09:15:12 CDT 2005

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;

Function Run(sCmd, sOutput)

Dim fso, fldTemp, sTempName, filTemp, filOutput, WshShell

Const TemporaryFolder = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(TemporaryFolder)
filTemp = fso.GetTempName
sTempName = fldTemp.Path & "\" & filTemp

'Run the command
Set WshShell = CreateObject("Wscript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Run = WshShell.Run( "cmd /c " & sCmd & " >" & sTempName, 0, True )

'Get the output from the command
Set filOutput = fso.OpenTextFile(sTempName, ForReading)
While Not filOutput.AtEndOfStream
sOutput = sOutput & filOutput.ReadLine
Wend
filOutput.Close

'Delete the temporary file
fso.DeleteFile sTempName

End Function




*** Sent via Developersdex http://www.developersdex.com ***

Re: Hellp with temp file by Torgeir

Torgeir
Mon May 30 09:43:43 CDT 2005

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:


'--------------------8<----------------------

sOutput = Run("ipconfig.exe /all")
WScript.Echo sOutput

sOutput = Run("fubarfoo")
WScript.Echo sOutput


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

'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Hellp with temp file by e

e
Tue May 31 18:26:27 CDT 2005

"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.

Re: Hellp with temp file by e

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