Ed
Tue Jul 15 04:51:29 CDT 2003
Since this script builds the HTML "on the go", it should work? I am not
sure, I was going to have it loop through all the services that I was
looking for until a key is pressed. I have yet to find a solid referance on
the differance between HTA and HTML.
"Ed" <glass walker theurge AT juno DOT com> wrote in message
news:u0rNBnjSDHA.2128@TK2MSFTNGP12.phx.gbl...
> Here is a rough of what I am trying to do. I had to comment the line that
> says "' and objExCmdStdOut.AtEndOfStream" otherwise I get an error I
can't
> trace. I am not getting a proper reading. When I command line it, I get
a
> proper result but the script is not pulling back the result.
>
> ' Author: Tony Hinkle
> ' tonyhinkle@yahoo.com
>
> ' The only original part I came up with is make the DIV element an
> ' object and change its innerHTML property. I'm sure someone else
> ' has done it, but I couldn't find an example anywhere.
>
> ' This capability makes IE an excellent output device for WSH.
> ' Output can be sent to IE, and it is not necessary to refresh or reload.
>
> ' I know it's sloppy--it's a sample that runs for 10 seconds...
>
> 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>Changing DIV's innerHTML from
> VBScript</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.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")
>
> 'Change the innerHTML of the DIV object
> ServiceStatus "\\VRC40ADP2", "PolicyAgent", STPolicyAgent
> objDiv.InnerHTML = "Policy Agent is : " & STPolicyAgent
> WScript.Sleep 4000
>
> 'Close IE and delete the file
> IE.Quit
> f1.Delete
>
> Sub SetupIE(File2Load)
> IE.Navigate File2Load
> IE.ToolBar = False
> IE.StatusBar = False
> IE.Resizable = False
>
> Do
> Loop While IE.Busy
>
> IE.Width = 500
> IE.Height = 110
> IE.Left = 0
> IE.Top = 0
> IE.Visible = True
> WshShell.AppActivate("Microsoft Internet Explorer")
> End Sub
>
> function ServiceStatus(strComputer, strService, Result)
> strOutput=Exec_Cmd( _
> "PSSERVICE \\" & strComputer & " query " & strService)
> if instr(strOutput,"STATE")=0 then
> Result = "NOTFOUND"
> elseif instr(strOutput,"STATE : 4 RUNNING")>0 then
> Result = "Running"
> else
> Result = "Stopped"
> end if
> end function
>
> Function Exec_Cmd(cmdline)
> ' thanks to Alex K. Angeloupoulos
> Set objShell = CreateObject("WScript.Shell")
> Set objExCmd = objShell.Exec("%COMSPEC% /C " & cmdline)
> Set objExCmdStdOut = objExCmd.StdOut
> Set objExCmdStdErr = objExCmd.StdErr
> Do: WScript.Sleep 10
> Do Until objExCmdStdOut.AtEndOfStream
> Exec_Cmd = Exec_Cmd & objExCmdStdOut.ReadAll
> CmdErr = CmdErr & objExCmdStdErr.ReadAll
> Loop
> Loop Until objExCmd.Status <> 0
> ' and objExCmdStdOut.AtEndOfStream
> end function
>
> "Ross Presser" <rpresser@NOSPAM.imtek.com.invalid> wrote in message
> news:Xns93B4A20E5B3BFpt101594@129.250.170.95...
> > "Ed" <glass walker theurge AT juno DOT com> wrote in
news:e5kMeQxRDHA.2056
> > @TK2MSFTNGP12.phx.gbl:
> >
> > > Unfortuantly WMI does not
> > > seem to work.
> >
> > If your servers are running NT4 (implied elsewhere in the thread), then
> > WMI is not installed by default. It will have to be installed first.
This
> > may not be allowed in your security environment.
> >
> > > I was looking at PSlist, couldn't I use your HTML thingy to
> > > do the same thing as WMI?
> >
> > I was referring to psservice rather than pslist, but either should work.
> > Below is a version of ServiceStatus() in vbscript that shells to
> > PSSERVICE. This will be expensive if you have a lot of services to
> > monitor! It has to start a process for each one...
> >
> > By the way, what I wrote has to be saved as XXXX.HTA, not XXX.HTML - it
> > has to run under the HTA environment, not a normal web browser.
> >
> > > I wrote a shell script with grep that checked for
> > > the existance of a thread, if it existed a variable was set to one.
> > > If the variable equalled one, I displayed it as up. Else down. I
> > > would think that I could do the same with this.
> >
> > why not use bash/grep here, too? Get bash and grep for Win32 from the
> > Cygwin project <
http://www.cygwin.com>, use psservice or pslist, and go
to
> > town. This sounds like it will be easiest for you with your current
> > experience.
> >
> > But here goes, ServiceStatus() using psservice:
> >
> > function ServiceStatus(strComputer, strService)
> > strOutput=Exec_Cmd( _
> > "PSSERVICE query \\" & strComputer & " " & strService)
> > if instr(strOutput,"STATE")=0 then
> > ServiceStatus = "NOTFOUND"
> > elseif instr(strOutput,"STATE : 4 RUNNING")>0 then
> > ServiceStatus = "Running"
> > else
> > ServiceStatus = "Stopped"
> > end if
> > end function
> >
> > Function Exec_Cmd(cmdline)
> > ' thanks to Alex K. Angeloupoulos
> > Set objShell = CreateObject("WScript.Shell")
> > Set objExCmd = objShell.Exec("%COMSPEC% /C " & cmdline)
> > Set objExCmdStdOut = objExCmd.StdOut
> > Set objExCmdStdErr = objExCmd.StdErr
> > Do: WScript.Sleep 10
> > Do Until objExCmdStdOut.AtEndOfStream
> > Exec_Cmd = Exec_Cmd & objExCmdStdOut.ReadAll
> > CmdErr = CmdErr & objExCmdStdErr.ReadAll
> > Loop
> > Loop Until objExCmd.Status <> 0
> > and objExCmdStdOut.AtEndOfStream
> > End Function
> >
> > --
> > Ross Presser -- rpresser AT imtek DOT com
> > "... VB is essentially the modern equivalent of vulgar Latin in 13th
> > Centurary Europe. Understand it, and you can travel to places you never
> > heard of and still understand some people." -- Alex K. Angelopoulos
>
>