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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WScript.Sleep and WScript.Echo

Status
Not open for further replies.

OraMs

Programmer
Feb 12, 2000
40
US
I execute a VBScript, using WScript.Sleep and WScript.Echo, at the command line with successful results. However, when I execute the same script from an application, I get the following VBScript run-time error message:

Object Required 'WScript'

As a matter of fact, any reference to WScript (WScript.CreateObject, WScript.Sleep, WScript.Echo, etc) generates the same error message. All feedback appreciated.

Thanks.

Here is a simple script I wrote to test:


dim WshShell

set WshShell = CreateObject("WScript.Shell")
WScript.Sleep 500
WScript.Echo "Successful!"

 
.VBS script files run within the Windows Script Host. You didnt specify what application you are executing the script, but I'll presume you meant within an ASP page using VBScript.
ASP pages are run within IIS, not WSH. Hence, all references to WScript are not valid. AFAIK, WScript is not creatable outside WSH.

FWIW, the following line of code in an ASP page should work, provided the WSH is installed on the machine:

set WshShell = CreateObject("WScript.Shell")

However, the following would fail:

set WshShell = WScript.CreateObject("WScript.Shell") Jon Hawkins
 
Create your object with this command:

set WshShell = Server.CreateObject("WScript.Shell")

.sleep and .echo are not supported i believe. . . br
Gerard
 
Thanks for your response Jon and Gerard.

I realize I did not provide sufficient information with my original inquiry so here it is. I'm using version 2.0 of WSH on WIN 98. My objective is to launch one healthcare application from another healthcare application using VBScript (I'm not using ASP page.) I am successful in the launching part. However, because I need to use the WshShell.SendKeys, I need to use Sleep or some other method to set and keep the focus on the launched application to ensure it receives the sent keys. Below is the code:

'global declarations
dim WshShell

Sub On_Script_Initialization()
'variable declarations
dim varFrontEnd
dim objNet
dim varUserName
dim varClaimID
dim varNow

'set up objects
set WshShell = CreateObject("WScript.Shell")

'load variables
varFrontEnd = WshShell.SpecialFolders.Item("Desktop")

'varFrontEnd = varFrontEnd + "\Diamon~1.lnk"
varFrontEnd = varFrontEnd + "\Claims~1.lnk"

'my work-around WSCRIPT.SLEEP but it does not work
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 3
wend

' launch application
WshShell.Run varFrontEnd, 1
WshShell.AppActivate &quot;WScript.Shell&quot;

WshShell.SendKeys &quot;{%}&quot; '<----- to test from/MACESS
'WshShell.SendKeys &quot;%&quot; '<---- to test from/RUN
WshShell.SendKeys &quot;{RIGHT}&quot;

End Sub

 
Continuation to previous thread...

I incorrectly wrote that the following statement does not work:


varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 1
wend


It does work. It needs to be placed after each statement. ex:


WshShell.SendKeys &quot;{ENTER}&quot;
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 1
wend

WshShell.SendKeys &quot;{F7}&quot;
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 1
wend

WshShell.SendKeys DocFlo.ClassificationValue(&quot;0110&quot;)
varNow = Now
while DateDiff(&quot;s&quot;,varNow,Now) < 1
wend


My problem is solved. Thanks again to those that replied.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top