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.
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.
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.
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
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?
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:
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.
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.