Link to home
Start Free TrialLog in
Avatar of PMGreensted
PMGreenstedFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript stops after 10 seconds in Windows 7

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

Avatar of Jamie_Wilson
Jamie_Wilson

On my W7 PC its fine, must be a local issue.

Might be a long shot, but try disabling UAC?
Avatar of RobSampson
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

ASKER CERTIFIED SOLUTION
Avatar of PMGreensted
PMGreensted
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good find. You could also run
wscript //T:00 //S
to save a zero time-out for your current user settings.
Regards,
Rob.