Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Timeout a VBScript?

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Timeout a VBScript?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Timeout a VBScript? - 12/17/2007 10:08:19 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well you could always use a vbscript to call the script that you want to time asyncronously. Then you would have the PID of the script that does all the real work and the parent script could kill it.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to humbletech99)
 
 
Post #: 21
 
 RE: Timeout a VBScript? - 12/17/2007 10:14:24 AM   
  dm_4ever


Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Executing a command using WScript.Shell and the Exec method will allow you to capture the PID of that process that is spawned.  WMI can also provide a PID. 

_____________________________

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 humbletech99)
 
 
Post #: 22
 
 RE: Timeout a VBScript? - 12/17/2007 10:15:41 AM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
yes that is a good idea, but I need this to be one script, self contained and distributable without dependency so I'd be more likely to look at spawning a shell.run or similar to run something to watch the original script and kill it upon the timeout, if possible.

Is it possible to execute some vbs from this script in an external process using something like shell.run or shell.exec to fork it off?

Is there any way to use threading in vbs to run this?

_____________________________

value(geeks) > value(mundanes)

(in reply to ebgreen)
 
 
Post #: 23
 
 RE: Timeout a VBScript? - 12/17/2007 10:19:53 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
You could execute an executeable that you wrote in VB. You could not execute raw code. If you want it all to be self contained in one file, then you have a couple of options. One is a self extracting executeable package that holds both files and extracts them at run time. Another is to have the parent script physically write the child file then run it. VBS does not support threading per se. At least not the way a more developed programming languages does. That sort of thread control simply isn't what vbscript is intended for.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to humbletech99)
 
 
Post #: 24
 
 RE: Timeout a VBScript? - 12/17/2007 10:38:40 AM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
this has all become too messy.

I am now scrapping the idea of the timeout, I will have to just break the coding guideline on this occasion, it's simply not worth the effort in this language...

_____________________________

value(geeks) > value(mundanes)

(in reply to ebgreen)
 
 
Post #: 25
 
 RE: Timeout a VBScript? - 12/17/2007 12:05:18 PM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
I don't understand: If the script needs to return a certain number for timeout and another number for complete execution, why it can't be 0 and 42 respectively?
Just modify the application monitoring the script so that it interpretates 0 as failure and any other number as success.
If that's not possible, launch the vbs through another vbs which will translate any other number into 0 and vice versa, then quit with the right number.
Such script takes 3 lines.

Note that for beter portability, it's better to avoid wmi...

_____________________________

Fred

(in reply to humbletech99)
 
 
Post #: 26
 
 RE: Timeout a VBScript? - 12/17/2007 8:21:55 PM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
yes I understand what you are saying, but it is not feasible to change the application that it integrates with and I want this to remain 1 script. It is more important in fact to maintain this in 1 clean script than to have the timeout feature.

Could you elaborate on why wmi is not portable? I thought all modern windoze had it?

_____________________________

value(geeks) > value(mundanes)

(in reply to Fredledingue)
 
 
Post #: 27
 
 RE: Timeout a VBScript? - 12/17/2007 9:08:45 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi humbletech99,

if you still are inclined to tinker with the timeout and have a lazy afternoon (weekend? holiday?)
coming, you may look at this:


      

output:


      

I' not sure about the appropriateness of WScript.Quit out of a class method and I wouldn't trust
this kind of code in a .wsf without carefull testing, but ...

Good luck! (either getting it to work for you or resisting to be lured into this voodoo)

ehvbs

(in reply to humbletech99)
 
 
Post #: 28
 
 RE: Timeout a VBScript? - 12/18/2007 10:38:41 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
quote:

yes I understand what you are saying, but it is not feasible to change the application that it integrates with and I want this to remain 1 script. It is more important in fact to maintain this in 1 clean script than to have the timeout feature.


You can keep it one script by letting the main script writing then launching the second script, then delete it.
Or use hta (vbscript embedded in hta application): With Hta you can launch a sub using SetInterval (sorry I don't remeber the code right now) and if past a certain time the sub close the window (and the script). The advantage with SetInterval is that other subs are still running in the meantime.
Hta, for this feature alone is your solution to your problem.

quote:

Could you elaborate on why wmi is not portable? I thought all modern windoze had it?

hmm,.. yes. "Only modern windoze" would be more exact. (I'm on w98se )
Beside that are you sure WMI works exactely the same from 2000 to Vista? That's just a thought. I'm no expert.


_____________________________

Fred

(in reply to humbletech99)
 
 
Post #: 29
 
 RE: Timeout a VBScript? - 12/18/2007 10:16:16 PM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
I had thought of embedding the creation of a new script and watching the timeout on that script to control the exit codes via the original parent script but this is quite an ugly workaround and I'd rather remove the timeout functionality altogether than do this.

I cannot use HTA as this needs to be a command line program and HTA is graphical in nature. Any popup would wreck this whole thing, as it's run non-interactively.

On WMI, firstly, what the heck are you doing with such a lame old Wintendo box??!!!

Secondly, I'm not sure it would be the same, but I'd be extremely surprised if it changed and so would pretty much all windows management programs. I think they will maintain current namespaces and simply extend or create new ones which is fine. I don't expect anything written today to not work on windows of the future.

< Message edited by humbletech99 -- 12/18/2007 10:22:55 PM >


_____________________________

value(geeks) > value(mundanes)

(in reply to Fredledingue)
 
 
Post #: 30
 
 RE: Timeout a VBScript? - 12/19/2007 3:17:34 AM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
ehvbs: sorry for the slow response on this, I am looking to integrate this but I don't know what it really does. Perhaps you can enlighten me?

Why are you creating this class and how is it really going to change the default exit code of the wscript.timeout. Does it replace some method that is called by the script terminator?

EDIT: Ah, I figured it out, very clever.

Thanks that works a treat.

Well Done and Thank You Again!

< Message edited by humbletech99 -- 12/19/2007 3:52:09 AM >


_____________________________

value(geeks) > value(mundanes)

(in reply to ehvbs)
 
 
Post #: 31
 
 RE: Timeout a VBScript? - 12/19/2007 5:15:22 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi humbletech99,

you are welcome. Thank you for your interest (and being my alpha tester).

For the record: a kind of explanation. The point about objects is that their destructors
are called when the go out of scope (or are destroyed 'manually'). If a timeout breaks the
script oExit.Class_terminate() is called. m_ErrorLevel was set to 42 in the constructor,
so WScript.Quit will be called with 42. The runtime may well be confused (2 terminations)
or simply set the exit code and proceed - I just don't now. Anyway, the 42 will reach the OS.

A 'good' run will execute the last line

   oExit.m_ErrorLevel = 0

so the destructor will WScript.Exit with 0. Writing this down I realize that there is a
possibility to improve the script (hint: 2 terminations). As my challenge topic kind of petered
out, I'll use this opportunity:

Hi all people willing to accept a challenge: Pimp my script/class!

Regards to all

ehvbs

(in reply to humbletech99)
 
 
Post #: 32
 
 RE: Timeout a VBScript? - 12/19/2007 10:44:22 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
humbletech99,
I'm pretty sure you can run an hta invisible, or at least minimized.
HTH

_____________________________

Fred

(in reply to ehvbs)
 
 
Post #: 33
 
 RE: Timeout a VBScript? - 12/19/2007 8:11:18 PM   
  humbletech99

 

Posts: 53
Score: 0
Joined: 6/9/2007
Status: offline
perhaps you are right, it just doesn't seem appropriate for a program that is going to be used by an external application which is limited to command line usage.

_____________________________

value(geeks) > value(mundanes)

(in reply to Fredledingue)
 
 
Post #: 34
 
 
Page:  <<   < prev  1 [2]
 
  

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 >> RE: Timeout a VBScript? Page: <<   < prev  1 [2]
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