Sleeping within an HTA-embedded script revisited 
Author Message
 Sleeping within an HTA-embedded script revisited

I would swear I posted a question a couple of weeks ago about emulating
"wscript.sleep" within an HTA - but I can't find it now.

I'm using an HTA as a "front end" for a tool to help in doing remote system
support; it performs nslookups, tracerts, portscans, etc on a remote system
and returns the results through use of Shell.Exec.

My problem is that the app "hangs" during extended traceroutes.  I would
like to transfer control during the trace so I can output a notice that a
trace is happening (possibly even display it character by character) - any
idea how?

Below are the relevant segments of the HTA; if you want to take a look at it
(or use it) you can get it from:

http://www.*-*-*.com/
(NOTE: Testing done on XP.  Need fscan from Foundstone to do the port scans)

=============================================
<script language="VBScript" type="text/vbscript">
<!--
                set objShell = CreateObject("WScript.Shell")
                strOut=""
                'Uncomment for Log Files (next 2 lines)
                'Set FSO = CreateObject("Scripting.FileSystemObject")
                'Set f = fso.OpenTextFile("C:\tmp.txt", 2, True)

                'TRACEROUTE
                sub traceroute
           cmdline="cmd /c tracert " & inTrace.value
                    Call ExternalCMDCall(cmdline,strOut)
                    outTrace.innerHTML= cmdline & " " & Timestamp & strOut
                end sub

                    Function ReplaceText(bad,good,str)
                        Set regEx = New RegExp            ' Create regular
expression.
                        regEx.Pattern = bad            ' Set pattern.
                        regEx.Global = True
                        regEx.Multiline = True
                        ReplaceText = regEx.Replace(str,good)   ' Make
replacement.
                    End Function

                    Sub Cleanup(strOut)
                        strOut = ReplaceText("[\f\n\r\v]+", "<br>",strOut)
' Make replacement.
                    End Sub

                    Sub ExternalCMDCall(cmdline,strOut)
                        set objExCmd = objShell.Exec(cmdline)
                        strOut=objExCmd.StdOut.ReadAll
                        Call Cleanup(strOut)

                    End Sub

     Function Timestamp
      Timestamp = "<b>" & Now() & "</b><br>"
     End Function
//-->

</script>

BODY SECTION
<table id="tblTracert"><tr><TD><i>Server Trace:</i></TD>
 <td><input size="24" id="inTrace"></td>
 <td><input id="submit2" onclick="traceroute" type="submit" value=" Tracert
"></td>
  <td><input id="btnTraceClear" onclick="TraceClear" type="submit"
value="Clear"></td>
</tr></table><div id=outTrace></div>



Mon, 03 May 2004 20:40:06 GMT  
 Sleeping within an HTA-embedded script revisited
You can use the window.SetTimeOut- or window.SetInterval-methodes to
sleep in a HTA.
However, as far as I know, it's not possible to update the display while
a script is executing.

Geert

Quote:
> -----Oorspronkelijk bericht-----

> without _
> _]
> Gepost om: donderdag 15 november 2001 13:40
> Gepost naar: wsh
> Discussie: Sleeping within an HTA-embedded script revisited
> Onderwerp: Sleeping within an HTA-embedded script revisited

> I would swear I posted a question a couple of weeks ago about
> emulating
> "wscript.sleep" within an HTA - but I can't find it now.

> I'm using an HTA as a "front end" for a tool to help in doing
> remote system
> support; it performs nslookups, tracerts, portscans, etc on a
> remote system
> and returns the results through use of Shell.Exec.

> My problem is that the app "hangs" during extended
> traceroutes.  I would
> like to transfer control during the trace so I can output a
> notice that a
> trace is happening (possibly even display it character by
> character) - any
> idea how?

> Below are the relevant segments of the HTA; if you want to
> take a look at it
> (or use it) you can get it from:

> http://www.bittnet.com/aka/files/rc6.hta
> (NOTE: Testing done on XP.  Need fscan from Foundstone to do
> the port scans)

> =============================================
> <script language="VBScript" type="text/vbscript">
> <!--
>                 set objShell = CreateObject("WScript.Shell")
>                 strOut=""
>                 'Uncomment for Log Files (next 2 lines)
>                 'Set FSO = CreateObject("Scripting.FileSystemObject")
>                 'Set f = fso.OpenTextFile("C:\tmp.txt", 2, True)

>                 'TRACEROUTE
>                 sub traceroute
>            cmdline="cmd /c tracert " & inTrace.value
>                     Call ExternalCMDCall(cmdline,strOut)
>                     outTrace.innerHTML= cmdline & " " &
> Timestamp & strOut
>                 end sub

>                     Function ReplaceText(bad,good,str)
>                         Set regEx = New RegExp            '
> Create regular
> expression.
>                         regEx.Pattern = bad            ' Set pattern.
>                         regEx.Global = True
>                         regEx.Multiline = True
>                         ReplaceText = regEx.Replace(str,good)   ' Make
> replacement.
>                     End Function

>                     Sub Cleanup(strOut)
>                         strOut = ReplaceText("[\f\n\r\v]+",
> "<br>",strOut)
> ' Make replacement.
>                     End Sub

>                     Sub ExternalCMDCall(cmdline,strOut)
>                         set objExCmd = objShell.Exec(cmdline)
>                         strOut=objExCmd.StdOut.ReadAll
>                         Call Cleanup(strOut)

>                     End Sub

>      Function Timestamp
>       Timestamp = "<b>" & Now() & "</b><br>"
>      End Function
> //-->

> </script>

> BODY SECTION
> <table id="tblTracert"><tr><TD><i>Server Trace:</i></TD>
>  <td><input size="24" id="inTrace"></td>
>  <td><input id="submit2" onclick="traceroute" type="submit"
> value=" Tracert
> "></td>
>   <td><input id="btnTraceClear" onclick="TraceClear" type="submit"
> value="Clear"></td>
> </tr></table><div id=outTrace></div>



Mon, 03 May 2004 22:00:14 GMT  
 Sleeping within an HTA-embedded script revisited



Quote:
> You can use the window.SetTimeOut- or window.SetInterval-methodes to
> sleep in a HTA.
> However, as far as I know, it's not possible to update the display while
> a script is executing.

here's a question about another possible approach then.

Right now, it looks like I am "hooking" myself to the shell job execution
due to the following:

set objExCmd = objShell.Exec(cmdline)
strOut=objExCmd.StdOut.ReadAll

Is there a way for me to just tell the script to execute the command and
continue on my way? If so, I guess I can go back and check for completion
regularly using SetInterval. Given this being possible, I would also need
another way to retrieve the completed results - I assume that any time I use
"ReadAll" I will be making it execute everything from scratch...



Mon, 03 May 2004 22:23:27 GMT  
 Sleeping within an HTA-embedded script revisited
You could use the 'objShell.Run-method' instead of the 'exec'-method.
This method has a 'WaitOnReturn'-argument. If set to 'False' the script
continues after starting the program.
The disadvantage of the 'run'-method is that it's not possible to catch
the output of the program. A workaround is to forward the output of the
program to a textfile, and read this file in your HTA.
It would have been nice if the 'Shell.Exec'-methode had the same options
as the 'Run'-method ('WindowStyle' and 'WaitOnReturn'). Maybe in a
future release of WSH???

Geert

Quote:
> -----Oorspronkelijk bericht-----

> without _
> _]
> Gepost om: donderdag 15 november 2001 15:23
> Gepost naar: wsh
> Discussie: Sleeping within an HTA-embedded script revisited
> Onderwerp: Re: Sleeping within an HTA-embedded script revisited



aan.vmma.be...
> You can use the window.SetTimeOut- or window.SetInterval-methodes to
> sleep in a HTA.
> However, as far as I know, it's not possible to update the display
while
> a script is executing.

here's a question about another possible approach then.

Right now, it looks like I am "hooking" myself to the shell job
execution
due to the following:

set objExCmd = objShell.Exec(cmdline)
strOut=objExCmd.StdOut.ReadAll

Is there a way for me to just tell the script to execute the command and
continue on my way? If so, I guess I can go back and check for
completion
regularly using SetInterval. Given this being possible, I would also
need
another way to retrieve the completed results - I assume that any time I
use
"ReadAll" I will be making it execute everything from scratch...



Tue, 04 May 2004 00:00:14 GMT  
 Sleeping within an HTA-embedded script revisited
I was afraid you were going to say that....

I'm hooked on using Shell.Exec, so I hope they do improve that.

A better alternative I think now is to simply instantiate a new browser
window and shove the output to it; that way I can release the original
Window immediately, the results echoed back won't change the "tool palette"
at all, and I can let the OS worry about how to juggle everythiug.  If
someone wants to cancel the scan, they can also just hit the "x" while it's
in progress.



Quote:
> You could use the 'objShell.Run-method' instead of the 'exec'-method.
> This method has a 'WaitOnReturn'-argument. If set to 'False' the script
> continues after starting the program.
> The disadvantage of the 'run'-method is that it's not possible to catch
> the output of the program. A workaround is to forward the output of the
> program to a textfile, and read this file in your HTA.
> It would have been nice if the 'Shell.Exec'-methode had the same options
> as the 'Run'-method ('WindowStyle' and 'WaitOnReturn'). Maybe in a
> future release of WSH???

> Geert

> > -----Oorspronkelijk bericht-----

> > without _
> > _]
> > Gepost om: donderdag 15 november 2001 15:23
> > Gepost naar: wsh
> > Discussie: Sleeping within an HTA-embedded script revisited
> > Onderwerp: Re: Sleeping within an HTA-embedded script revisited



> aan.vmma.be...
> > You can use the window.SetTimeOut- or window.SetInterval-methodes to
> > sleep in a HTA.
> > However, as far as I know, it's not possible to update the display
> while
> > a script is executing.

> here's a question about another possible approach then.

> Right now, it looks like I am "hooking" myself to the shell job
> execution
> due to the following:

> set objExCmd = objShell.Exec(cmdline)
> strOut=objExCmd.StdOut.ReadAll

> Is there a way for me to just tell the script to execute the command and
> continue on my way? If so, I guess I can go back and check for
> completion
> regularly using SetInterval. Given this being possible, I would also
> need
> another way to retrieve the completed results - I assume that any time I
> use
> "ReadAll" I will be making it execute everything from scratch...



Tue, 04 May 2004 00:19:33 GMT  
 Sleeping within an HTA-embedded script revisited
1) install the ScriptX component (www.meadroid.com/scriptx)
2) within the HTA create a page level instance of "scriptx.factory"
3) use -> factory.wait 0 <- at points where you want your DHTML changes to be rendered

There is a *lot* of great functionality in the ScriptX free feature set.  You only need a license if you want to use advance HTML printing features.

--
Michael Harris
Microsoft.MVP.Scripting


Quote:
> You can use the window.SetTimeOut- or window.SetInterval-methodes to
> sleep in a HTA.
> However, as far as I know, it's not possible to update the display while
> a script is executing.

> Geert

> > -----Oorspronkelijk bericht-----

> > without _
> > _]
> > Gepost om: donderdag 15 november 2001 13:40
> > Gepost naar: wsh
> > Discussie: Sleeping within an HTA-embedded script revisited
> > Onderwerp: Sleeping within an HTA-embedded script revisited

> > I would swear I posted a question a couple of weeks ago about
> > emulating
> > "wscript.sleep" within an HTA - but I can't find it now.

> > I'm using an HTA as a "front end" for a tool to help in doing
> > remote system
> > support; it performs nslookups, tracerts, portscans, etc on a
> > remote system
> > and returns the results through use of Shell.Exec.

> > My problem is that the app "hangs" during extended
> > traceroutes.  I would
> > like to transfer control during the trace so I can output a
> > notice that a
> > trace is happening (possibly even display it character by
> > character) - any
> > idea how?

> > Below are the relevant segments of the HTA; if you want to
> > take a look at it
> > (or use it) you can get it from:

> > http://www.bittnet.com/aka/files/rc6.hta
> > (NOTE: Testing done on XP.  Need fscan from Foundstone to do
> > the port scans)

> > =============================================
> > <script language="VBScript" type="text/vbscript">
> > <!--
> >                 set objShell = CreateObject("WScript.Shell")
> >                 strOut=""
> >                 'Uncomment for Log Files (next 2 lines)
> >                 'Set FSO = CreateObject("Scripting.FileSystemObject")
> >                 'Set f = fso.OpenTextFile("C:\tmp.txt", 2, True)

> >                 'TRACEROUTE
> >                 sub traceroute
> >            cmdline="cmd /c tracert " & inTrace.value
> >                     Call ExternalCMDCall(cmdline,strOut)
> >                     outTrace.innerHTML= cmdline & " " &
> > Timestamp & strOut
> >                 end sub

> >                     Function ReplaceText(bad,good,str)
> >                         Set regEx = New RegExp            '
> > Create regular
> > expression.
> >                         regEx.Pattern = bad            ' Set pattern.
> >                         regEx.Global = True
> >                         regEx.Multiline = True
> >                         ReplaceText = regEx.Replace(str,good)   ' Make
> > replacement.
> >                     End Function

> >                     Sub Cleanup(strOut)
> >                         strOut = ReplaceText("[\f\n\r\v]+",
> > "<br>",strOut)
> > ' Make replacement.
> >                     End Sub

> >                     Sub ExternalCMDCall(cmdline,strOut)
> >                         set objExCmd = objShell.Exec(cmdline)
> >                         strOut=objExCmd.StdOut.ReadAll
> >                         Call Cleanup(strOut)

> >                     End Sub

> >      Function Timestamp
> >       Timestamp = "<b>" & Now() & "</b><br>"
> >      End Function
> > //-->

> > </script>

> > BODY SECTION
> > <table id="tblTracert"><tr><TD><i>Server Trace:</i></TD>
> >  <td><input size="24" id="inTrace"></td>
> >  <td><input id="submit2" onclick="traceroute" type="submit"
> > value=" Tracert
> > "></td>
> >   <td><input id="btnTraceClear" onclick="TraceClear" type="submit"
> > value="Clear"></td>
> > </tr></table><div id=outTrace></div>



Tue, 04 May 2004 13:23:11 GMT  
 Sleeping within an HTA-embedded script revisited
You are meaning asynchronous operation between your main script and the
program launched by your script. In this case, you can use the Run method
of the WSH by specifying the bWaitOnReturn paramter with False.

The Run method returns an integer. The Run method starts a program running
in a new Windows process. You can have your script wait for the program to
finish execution before continuing. This allows you to run scripts and
programs synchronously. Environment variables within the argument
strCommand are automatically expanded. If a file type has been properly
registered to a particular program, calling run on a file of that type
executes the program. For example, if Word is installed on your computer
system, calling Run on a *.doc file starts Word and loads the document. The
following table lists the available settings for intWindowStyle.

The following VBScript code specifies the window type, without waiting for
Notepad to be shut down by the user.

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)

Regards,

This posting is provided ?AS IS?, with no warranties, and confers no
rights.



Sat, 08 May 2004 17:27:03 GMT  
 Sleeping within an HTA-embedded script revisited
Exec needs to be used to return the output.

Quote:
> You are meaning asynchronous operation between your main script and the
> program launched by your script. In this case, you can use the Run method
> of the WSH by specifying the bWaitOnReturn paramter with False.

> The Run method returns an integer. The Run method starts a program running
> in a new Windows process. You can have your script wait for the program to
> finish execution before continuing. This allows you to run scripts and
> programs synchronously. Environment variables within the argument
> strCommand are automatically expanded. If a file type has been properly
> registered to a particular program, calling run on a file of that type
> executes the program. For example, if Word is installed on your computer
> system, calling Run on a *.doc file starts Word and loads the document.
The
> following table lists the available settings for intWindowStyle.

> The following VBScript code specifies the window type, without waiting for
> Notepad to be shut down by the user.

> Set WshShell = WScript.CreateObject("WScript.Shell")
> Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)

> Regards,

> This posting is provided ?AS IS?, with no warranties, and confers no
> rights.



Tue, 11 May 2004 11:36:45 GMT  
 Sleeping within an HTA-embedded script revisited
Try Geert's suggestion.

This posting is provided ?AS IS?, with no warranties, and confers no
rights.



Fri, 21 May 2004 10:35:43 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Sleep Within Script Causing program to crash

2. Drag and drop, imager.hta revisited

3. How to create a sleep in an HTA (wscript.sleep doesn't work in HTA...)

4. wscript.sleep in HTA

5. Sleep in HTA

6. HTA - Sleep

7. Sizing HTA windows around embedded ActiveX controls

8. Scripting HTA's HTA:APPLICATION Navigable property

9. embedding a type1 font within a postscript file

10. VBScript embedded within JavaScript

11. VBScript embedded within JavaScript

12. scrID within embedded lists

 

 
Powered by phpBB® Forum Software