Solved

VBScript stops after 10 seconds in Windows 7

Posted on 2010-08-16
4
687 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

OfficeMate Freezes on login or does not load after login credentials are input.
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 video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

687 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