PMGreensted
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.
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
Hi, this works fine for me on Windows 7...
I haved added
If WshShell.AppActivate("note pad") = 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.
I haved added
If WshShell.AppActivate("note
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good find. You could also run
wscript //T:00 //S
to save a zero time-out for your current user settings.
Regards,
Rob.
wscript //T:00 //S
to save a zero time-out for your current user settings.
Regards,
Rob.
Might be a long shot, but try disabling UAC?