Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script gets hung-up and IE alerts "script causing IE to run slowly"

Status
Not open for further replies.

oltran

Technical User
Dec 26, 2002
19
US
Hi, I am tring to automate and streamline some processes at my job so I created an HTML document that uses javascript to compile information from a form and pass it to a vbscript function to execute. I use notepad as a testing program to receive the sent keys. My program works like a champ on my computer but on a co-worker's computer the script gets "hung-up" and internet explorer pops up with a message that says:

"A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

A sample of the program I have is below. It seems to get hung-up and displays the IE message after it executes this line of code: 'ss.SendKeys strPassword'

function wait()
Dim starttime, currenttime, waittime
waittime = 3
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
end function
function PassValues
Dim ss, strUserName, strPassword, strPassedValue
strUserName = document.form.UserName.value + "{enter}"
strPassword = document.form.Password.value + "{enter}"
strPassedValue = document.form.output.value
Set ss = CreateObject("WScript.Shell")
ss.run "C:\WINNT\NOTEPAD.EXE",1
wait()
ss.SendKeys strUserName
wait()
ss.SendKeys strPassword
wait()
ss.SendKeys "1{enter}JOBREQUEST{enter}3" + strPassedValue
Set ss = nothing
end function

Thanks for your time,
Jason
 
Maybe notepad is not where you think it is on your coworkers computer? Do you even get it open? Where does it hang? Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
It's sad that some Americans proudly turn their backs on the very Flag the gives them the opportunity to do just that... - Mike
 
When you get a msg like:

"A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

It usually means that you have a loop that is not ending. You should look at your loop code(s) and see if there is an instance where the loop can run forever.

My 2 cents
"did you just say Minkey?, yes that's what I said."

MrGreed
 
Yes, notepad does startup and sendkeys works and types the username & password, but it hangs-up after that and doesn't execute the last sendkeys statement.

The only loop I am using is in the wait() function, and it works the first two times it is called but I'm not sure what goes wrong inbetween ss.SendKeys strPassword and ss.SendKeys "1{enter}JOBREQUEST{enter}3" + strPassedValue.

I did read on microsoft's website that Internet Explorer will display this error message whe 5,000,000 script statements are executed. Could my wait() function that is called 3 times make my script hit this 5,000,000 limit before it executes the third wait()?

ss.run "C:\WINNT\NOTEPAD.EXE",1
wait()
ss.SendKeys strUserName
wait()
ss.SendKeys strPassword '<--this is the last line of code that I can see execute properly, or could it be the last wait() function?
wait()
ss.SendKeys &quot;1{enter}JOBREQUEST{enter}3&quot; + strPassedValue
 
Never implement a Wait/Pause/Sleep function in the form of a cycling Do loop as you have above. It may achieve the same result, but it's not processor friendly.

1) Using SQLServer,

Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.open MyDsn

conn.Execute(&quot;WAITFOR DELAY '000:00:05'&quot;)

conn.Close
set conn = Nothing

2) Using VBS:
Set WSHShell = CreateObject(&quot;WScript.Shell&quot;)
wshshell.run &quot;cscript.exe C:\yourscript.vbs&quot;,0,True

where C:\yourscript.vbs contains the following line of code

WScript.Sleep 5000

3) Create a COM component that wraps the Win32 API Sleep function. Jon Hawkins
 
FWIW, you didn't state whether this HTML document is a web page (being served by a webserver) or just an HTML document on a file server or the client PCs. If the latter, you may want to explore using an HTA, which are not subject to as many of the security restrictions as an HTM webpage.

Jon Hawkins
 
Thanks for the information, I had a feeling that the processor didn't like that I had those wait loops in there like that. I'm gonna try this with my script!

many thanks!
Jason
 
This file will not be on the I plan on having it on an intranet server like file://Server/form.htm or if necessary have my co-workers save it locally, like file:///c:\form.htm. I never heard of HTA, Ill check it out.

Thanks again!
Jason
 
An HTA will have the same limitations as an HTM.

There isn't any true Sleep( ) method available in IE. I have found only two options:

* Something like the SQL thing johnscott8 suggested.

* An ActiveX wrapper for the Sleep( ) function in the Win32 API. This can be created in VB 5 or 6, but you'll need the VB runtimes installed on your target machine(s). Somebody with Delphi 4 or later could make a nice compact one for you but it still needs to be installed on target machines.

In general it is better to use event-driven logic in an HTA wherever possible. Whenever you can avoid things like SendKeys too - these are not highly reliable. Instead of NotePad you'd want to use something with an automation interface such as Word.

We don't always get what we want though.

Hopefully the real program you want to drive with this script has an automation interface.
 
I don't know anything about API, is there any tutorial sites out there that I could learn from? I looked but didn't come up with anything.

I don't have access to the companys SQL because I'm not an IS guy. I'm just able to put this file out there and let everyone access it through the server folder.

I am using notepad because the actual program we are using is similar to a DOS prompt, whenever it is activated any keys sent to it will execute functions needed. I wrote this program because the form will allow users to freely copy and past information in it and then it will translate the information to the program we use.

Thanks for all the help, maybe Ill know where to look to perfect this little app I'm doing now. Its so frustrating to write something for so long just to see it fail on other computers!

Jason
 
Didn't mean to leave you hanging.

If you could live with deploying a free component with your HTM/HTA solution, you might look at ToolSack.Sleeper


You can download the installer here too. Click on their logo on the page above, navigate to &quot;download&quot;. It's an MSI file, just double-click to start the setup.

Toolsack Baseline will have MORE than you need.

Other sources for similar scriptable components exist too.

I'm like you though, I'd prefer a native solution.
 
jonscott8,

I used your second method with the 'wshshell.run &quot;cscript.exe C:\yourscript.vbs&quot;,0,True' and it works great on my home computer! On Monday comes the moment of truth when I try it at work with that computer that gave me problems with my original code.

I wonder why the 'WScript.Sleep 5000' statement runs in a file that has the .vbs just fine but when transferred to an HTM/HTA document we get that error message? Is there a security issue that I'm not aware of or just a bug?

Thanks!
Jason
 
Yuck, ptui!

Pretty darned ugly but it'll work. Has to be better than burning cycles in a wait loop, but man!

oltran there's no bug here at all. That Sleep( ) method is intrinsic to Windows Script Host.

You aren't scripting Windows Script Host, you're scripting Internet Explorer. IE doesn't expose anything like a Sleep( ) that I've been able to discover, and from my own efforts to find one (I've Googled the heck out of the web several times looking for this, been all through MSDN, etc.) I guess nobody else ever has either.

I really hate that solution but I sure can't argue with success. One recommendation: consider wrapping it in your own subroutine called Sleep( ) or GoSleep( ) or something. Then if a better answer comes along you can just update the subroutine.
 
Hello again,

It works on the computer at work! But only when the .vbs file is saved locally (c:\wait.vbs). Is there a way use this file in a server folder like \\Server\wait.vbs or file:///\\Server\wait.vbs so I can edit the file without having to update everyones computer? I tried these but the file is ignored when the program is ran.

Thanks again,
Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top