Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Pause in HTA - setInterval, proper object

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,50032
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pause in HTA - setInterval, proper object
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Pause in HTA - setInterval, proper object - 7/26/2007 7:17:38 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
I could use some help with a pause in an HTA that I am building. I want to poll the status of a service after sending it a stop (or start) command before continueing my script. I tried using sleeps (launching external sleep script), but I really need to check the status since some service stop or start sooner than others. The following snippet is of two functions that I am using.

I am using a setInterval process to pause and repoll the service state. I was using a while loop in the ServiceState() function, but that was causing the script to hang. I just need to identify the proper way to implement the setInterval and clearInterval method. Most likely, I just need to identify what object is should bind to.

When I run the script, it loops to the ServiceState function once (the return is false because state shows Stop Pending) and then presents me with an error stating Invalid Argument on the line  oPause = setInterval(ServiceState(strComputer,objService.Name,"stopped"),5000). This seems strange to me since it completes the function call once.
The output is:
<Error pops up here>
Service state: Stop Pending
ServiceControl: stopping process
- Stopping ServiceControl on server1
- Service(s) selected are 'ServiceControl'
*** Restarting services on server1 ***
This section will display script status



This function stops a service and all dependant services


      

This function polls the computer for service state

      

< Message edited by CondoPC -- 7/26/2007 8:30:56 AM >
 
 
Post #: 1
 
 RE: Pause in HTA - setInterval, proper object - 7/26/2007 6:53:04 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
I use this bit of code to check that a service is stopped

This one, for example, stops and restarts the BITS service.

The only problem you'll have with it that you can't use Wscript.Sleep in an HTA.  So you'll need to define your own Sleep routine.

This thread will help http://www.visualbasicscript.com/m_48600/tm.htm


      

< Message edited by ginolard -- 7/26/2007 6:54:27 PM >


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to CondoPC)
 
 
Post #: 2
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 12:49:50 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
I like that, thanks. I just need to identify the setInterval and clearInterval process. I have been toubleshooting this for about a day. I don't like the "sleep by launching external script" method because it pops up windows and can be distracting to the admin maiking them think something else is happening.

(in reply to ginolard)
 
 
Post #: 3
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 1:09:36 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you execute and external sleep script using something like

objShell.Run "cscript.exe sleep.vbs 5000", 0, True

It shouldn't pop anything and personally, if you want to give your HTA some time that's the method I prefer.

http://www.w3schools.com/htmldom/met_win_setinterval.asp

< Message edited by dm_4ever -- 7/27/2007 1:10:46 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to CondoPC)
 
 
Post #: 4
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 2:06:20 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
OK, this what I have discovered:

1 - the object for the setInterval can be window - command would be like: oPause = window.setInterval("Subroutine", mSec)

2 - the clear command does not need to be assigned to a variable at can be implemented like this: window.clearInterval(oPause)

3 - the reason I as getting Invalid Arguments was because the subroutine cannot have parameters defines in it (ref. http://www.microsoft.com/technet/scriptcenter/topics/htas/autorefresh.mspx)
     Valid :  oPause = window.setInterval("ServiceState",5000)
   Invalid: oPause = window.setInterval(ServiceState(strComputer,objService.Name,"running"),5000)

4 - and the last thing I found out that makes this all not work - this pause-loop run Asynchronous to the rest of the script. In other words, it
   completed the stop and start whether or not the sub function actually saw the service stop.

My code is below


      



< Message edited by CondoPC -- 7/27/2007 2:12:14 AM >

(in reply to CondoPC)
 
 
Post #: 5
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 2:10:51 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
the problem is that cscript runs in a command window, so on my system it pops up a command window every time it launches the sleep script.

my sleep script is below


'=== Pause the script for desired milliseconds ==

Sub
ScriptSleep(MSecs)
Set fso = CreateObject("Scripting.FileSystemObject")
strText =
"Please wait while the service responds"

If Fso.FileExists("sleeper.vbs")=False Then

Set objOutputFile = fso.CreateTextFile("sleeper.vbs", True)
objOutputFile.Write
"wscript.echo " & strText
objOutputFile.Write
"wscript.sleep WScript.Arguments(0)"

objOutputFile.Close
End If

CreateObject(
"WScript.Shell").Run "sleeper.vbs " & MSecs,1 , True
End
Sub



I notice that you used objShell.Run commandline, 0, True - I am using 1 - that must be why mine display and yours is hidden. Thanks for the info, I will have to use it since setInterval is not working for me based on my findings.

(in reply to dm_4ever)
 
 
Post #: 6
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 3:29:12 AM   
  Rischip


Posts: 510
Score: 2
Joined: 3/26/2007
Status: offline
% of CPU usage is not a Single metric to judge a function.
When the CPU is at "100%" usage, is the system still responsive ?


_____________________________

Rischip
Author of - The Grim Linker

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 6:51:23 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
Rischip, I am not sure your what your getting at. If you are refering to my "hang", it meant that the script looped infinitely and the MSHTA was unresponsive and would not refresh the window.

With the script samples in this post and others, I was able to complete my first HTA script that performs service management with on-screeen output and status. It even disables and changes the text of buttons while running. Once I get it cleansed of company specific data, I'll post it into the script library. Thanks all!


(in reply to Rischip)
 
 
Post #: 8
 
 RE: Pause in HTA - setInterval, proper object - 7/27/2007 7:29:39 AM   
  Rischip


Posts: 510
Score: 2
Joined: 3/26/2007
Status: offline
My bad, I posted this in the wrong spot. It was meant toward the HTA wscript.sleep kludges that people have come up with. Some of the best ones spike the CPU, but have no effect on system responsiveness.
I had too many windows open and like an i diot posted in the wrong one.

< Message edited by Rischip -- 7/27/2007 7:30:55 AM >


_____________________________

Rischip
Author of - The Grim Linker

(in reply to CondoPC)
 
 
Post #: 9
 
 RE: Pause in HTA - setInterval, proper object - 7/30/2007 4:18:23 AM   
  Skie

 

Posts: 58
Score: 0
Joined: 3/2/2006
Status: offline
Typed but not tested solution using setInterval.  If it doesn't work, it should be really close to something that will work.  You may need to add a check to the StopService function to skip processes that have been stopped.

      

(in reply to CondoPC)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pause in HTA - setInterval, proper object Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts