?
Solved

VBScript stops after 10 seconds in Windows 7

Posted on 2010-08-16
4
Medium Priority
?
691 Views
Last Modified: 2012-05-10
I usually only write scripts for Windows servers and have just found that any script I run on my Win 7 PC runs OK unless the execution time is longer than 10 seconds.
I think I'm missing something obvious and suspect it's either a security setting or limitation I'm not aware of.
On my Win 7 PC the script below will just stop short of 10 seconds, but on a Win 2003 server it will complete.
Option Explicit
Dim WshShell, i, StartTime, ScriptTime
StartTime = Timer()
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "notepad"

WScript.Sleep 1000

WshShell.AppActivate "notepad"

For i = 1 To 100
	ScriptTime = FormatNumber(timer() - StartTime, 2)
	WshShell.SendKeys "Test "& i & " - " & ScriptTime & " seconds{ENTER}"
	WScript.Sleep 1000
Next

WScript.Quit

Open in new window

0
Comment
Question by:PMGreensted
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Jamie_Wilson
ID: 33450526
On my W7 PC its fine, must be a local issue.

Might be a long shot, but try disabling UAC?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33450714
Hi, this works fine for me on Windows 7...
I haved added
 If WshShell.AppActivate("notepad") = True Then
because you don't want to be sending keystrokes to any application that is not the one you want in focus....
Regards,
Rob.

Option Explicit
Dim WshShell, i, StartTime, ScriptTime
StartTime = Timer()
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "notepad"

WScript.Sleep 1000

For i = 1 To 100
	If WshShell.AppActivate("notepad") = True Then
		ScriptTime = FormatNumber(timer() - StartTime, 2)
		WshShell.SendKeys "Test "& i & " - " & ScriptTime & " seconds{ENTER}"
		WScript.Sleep 1000
	End If
Next

WScript.Quit

Open in new window

0
 

Accepted Solution

by:
PMGreensted earned 0 total points
ID: 33453388
Good point about adding 'If WshShell.AppActivate("notepad") = True' although my script was only for testing the timout.

I've now played around and found I could get it working by running from the command line with the //T:nn      (Time out in seconds) switch set to a high enough value. e.g.

cscript C:\Sendkeys_Test.vbs //T:100

However, I've found the actual reason for the problem on my PC was the Windows Script Host settings in the registry:

[HKEY_CURRENT_USER\Software\Microsoft\Windows Script Host\Settings]
"Timeout"=dword:0000000a (10)
"DisplayLogo"=dword:00000001 (1)
"Flags"=dword:000003e8 (1000)

Increasing the Timeout obviously increases the default timeout if I were to run a script without a switch.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33459501
Good find. You could also run
wscript //T:00 //S
to save a zero time-out for your current user settings.
Regards,
Rob.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question