Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


vbs functions in hta?

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbs functions in hta?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 vbs functions in hta? - 5/11/2007 4:52:21 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Do VBS Funtions work in hta?  I have an vbs script that uses a function but when I try to put it in hta, it gets an error.  Thanks to anyone who can help.
 
 
Post #: 1
 
 RE: vbs functions in hta? - 5/11/2007 5:18:33 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Yes, what line give you an error?

Is it something like WScript.Sleep or WScript.CreateObject("WScript.Shell")?

_____________________________

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 ekrengel)
 
 
Post #: 2
 
 RE: vbs functions in hta? - 5/11/2007 5:30:51 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
This is what I have...but it is saying there is an error at the start of "Function":


      

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: vbs functions in hta? - 5/11/2007 6:08:34 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Hi,

I.  You can't have a function inside your sub
       A.Move you Function Ping outside the Sub...End Sub
II.  You can't use WScript.Quit or WScript.Sleep in an HTA
      A.  Use Exit Sub instead of WScript.Quit to exit the Sub
      B.  You will need to find another way to pause your script.
           Do a search in this forum and you should find examples of this.

_____________________________

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 ekrengel)
 
 
Post #: 4
 
 RE: vbs functions in hta? - 5/11/2007 6:42:07 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Thanks.  I moved the function out of the sub...and I searched the forms and found this command:

window.setTimeout 1000

But it does not work in a loop, which is what I need.  I looked at this post:

http://www.visualbasicscript.com/m_26437/mpage_1/key_WScript.Sleep/tm.htm#26437

I have not been able to find anything else...can someone help?

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: vbs functions in hta? - 5/11/2007 7:42:13 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I know I saw a recent post with an alternative sleep method for an HTA but can't find it so here you go...

Sleep 5

Sub Sleep(strTimeWait)
   Dim objShell : Set objShell = CreateObject("WScript.Shell")
   objShell.Run "%comspec% /c ping.exe 127.0.0.1 -w 1000 -n " & _
                strTimeWait + 1, 0, True
End Sub

Instead of using WScript.Sleep 5000 to pause for 5 seconds you would use Sleep 5
Note: this method is not exact in terms of the length of the pause, but it is close enough for most people.

I did find the post where ebgreen said he felt dirty using a method like this though.

_____________________________

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 ekrengel)
 
 
Post #: 6
 
 RE: vbs functions in hta? - 5/11/2007 8:14:12 AM   
  DiGiTAL.SkReAM


Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Another way of doing a "loop" in an hta is like this:
iTimerID = window.setInterval(NameOfSubToRun, TimeToWaitBetweenLoops, "VBScript")

Example:

      

In this example, the iTimerID loop checks the value of the bContinueVariable once a second.

You can have several of these timers running at the same time, just create them as iTimerID1, iTimerID2, iTimerID3, etc.  Of course, you can use your own names, but the theory is the same.  The TimeToWaitBetweenLoops variable is counted as 1000 = 1 second, just like wscript.sleep.


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: vbs functions in hta? - 5/14/2007 3:08:13 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
I'm still having trouble with this...I'm not sure how to integrate what you guys gave me into what I have....this is what I have:


      

I already have a function that does the ping...I just need the sleep part...

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 8
 
 RE: vbs functions in hta? - 5/15/2007 12:23:06 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Can anyone help?

(in reply to ekrengel)
 
 
Post #: 9
 
 RE: vbs functions in hta? - 5/15/2007 12:29:33 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
What's not working? Any errors?

_____________________________

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 ekrengel)
 
 
Post #: 10
 
 RE: vbs functions in hta? - 5/15/2007 12:56:58 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
No it doesn't get any errors, which is why its hard to understand whats going wrong...but the ping function that I have still doesn't seem to be working.  It works in a stand alone .vbs script, but not in here.  Also, mshta.exe seems to hang and I have to kill the process to stop it.  Should I post the ping function?

(in reply to ekrengel)
 
 
Post #: 11
 
 RE: vbs functions in hta? - 5/15/2007 1:17:02 AM   
  DiGiTAL.SkReAM


Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Post the entire thing so that we can help.  It is hard to trobuleshoot fragments of code.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ekrengel)
 
 
Post #: 12
 
 RE: vbs functions in hta? - 5/15/2007 1:51:57 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Ok here is the entire script.  I've just been messing around with the restart section for now untill I get that to work, and then I'll do the same for the shutdown section:


      

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 13
 
 RE: vbs functions in hta? - 5/15/2007 2:10:45 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I tried your HTA without executing the shutdown.exe.

The HTA seems unresponsive because it is waiting for the PC to be unreachable.  I put the IP of my second PC, pressed the Restart button, had it show me the shutdown command rather than execute it, then I disabled the adapter on that second PC to simulate it being off, and the HTA detected it and showed your msgbox.

_____________________________

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 ekrengel)
 
 
Post #: 14
 
 RE: vbs functions in hta? - 5/15/2007 2:20:32 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Ok...what do I need to do?  I've tested this and the PC was shutdown and didn't respond with a msgbox...

(in reply to dm_4ever)
 
 
Post #: 15
 
 RE: vbs functions in hta? - 5/15/2007 2:57:11 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You can start by removing the On Error Resume Next.

Maybe put a msgbox in the other subs to make sure they are being called.

_____________________________

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 ekrengel)
 
 
Post #: 16
 
 RE: vbs functions in hta? - 5/15/2007 3:08:12 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
I removed "on error resume next" and put msgbox's in the beginning of the sub's, and I am still not getting any errors or msgbox's that come up....

(in reply to dm_4ever)
 
 
Post #: 17
 
 RE: vbs functions in hta? - 5/15/2007 3:24:34 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Where did you put a msgbox?

I would probably put one in your Do While Ping(....  to see if it is getting this far.
Perhaps another in the Ping sub to see if it is being executed and another in the Sleep.

_____________________________

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 ekrengel)
 
 
Post #: 18
 
 RE: vbs functions in hta? - 5/15/2007 4:34:01 AM   
  ekrengel

 

Posts: 28
Score: 0
Joined: 5/11/2007
Status: offline
Ok, so I put a msgbox in pretty much every sub, and in the "do while" and I am still getting nothing...it looks like it stops at the do while....

(in reply to dm_4ever)
 
 
Post #: 19
 
 RE: vbs functions in hta? - 5/15/2007 5:30:48 AM   
  dm_4ever


Posts: 2724
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
So what if you removed the True in your .Run so that it doesn't wait? Perhaps this is where it is getting stuck.

_____________________________

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 ekrengel)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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 >> vbs functions in hta? Page: [1] 2   next >   >>
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