I'm running a simple script that:

- Launches an app
- AppActivates the app (using a loop until it is loaded)
- sleep for a second
- then sends keystrokes to the application.

Here's the code:

Set objShell = WScript.CreateObject("WScript.Shell")
cnt=1
Do Until Success = True
Success = objShell.AppActivate("My App")
wscript.sleep 250
cnt=cnt+1
if cnt>40 then
Success = True
end if
Loop
if cnt>40 then
msgbox "App did not launch within 10 seconds"
else
Wscript.Sleep 300
objShell.SendKeys "somekeystrokes{ENTER}"
end if

The problem is that somehow the application is getting hung up with
the script. As long as the script is running, the application is
non-responsive. It will launch...but then it freezes and the screen
doesn't completely draw. As soon as the script errors out and I close
it...the app comes alive.

I'm assuming that the app and wscript.exe are running in the same
memory space and are interfering with each other. Is there a way to
run the script in its own memory space so it will not interfere with
the app.

Or is there another problem that I'm missing?

Thanks for any advice,

Walt

Re: Is it possible to run a VBscript in its own memory space? by Andrew

Andrew
Mon Jan 19 01:31:22 CST 2004

What is the app that you are launching? This seems to be missing from your
script.

Use the 'Run' method to launch your exe, sleep for a while, then use
AppActivate passing the window title of your app's main window. Don't advise
using a loop. If you want more time, increase the value passed to
wscript.sleep between objShell.Run and objShell.AppActivate.

Andrew


"Walt Stringer" <w_stringer@yahoo.com> wrote in message
news:4606ee59.0401161235.1a29ac35@posting.google.com...
> I'm running a simple script that:
>
> - Launches an app
> - AppActivates the app (using a loop until it is loaded)
> - sleep for a second
> - then sends keystrokes to the application.
>
> Here's the code:
>
> Set objShell = WScript.CreateObject("WScript.Shell")
> cnt=1
> Do Until Success = True
> Success = objShell.AppActivate("My App")
> wscript.sleep 250
> cnt=cnt+1
> if cnt>40 then
> Success = True
> end if
> Loop
> if cnt>40 then
> msgbox "App did not launch within 10 seconds"
> else
> Wscript.Sleep 300
> objShell.SendKeys "somekeystrokes{ENTER}"
> end if
>
> The problem is that somehow the application is getting hung up with
> the script. As long as the script is running, the application is
> non-responsive. It will launch...but then it freezes and the screen
> doesn't completely draw. As soon as the script errors out and I close
> it...the app comes alive.
>
> I'm assuming that the app and wscript.exe are running in the same
> memory space and are interfering with each other. Is there a way to
> run the script in its own memory space so it will not interfere with
> the app.
>
> Or is there another problem that I'm missing?
>
> Thanks for any advice,
>
> Walt



Re: Is it possible to run a VBscript in its own memory space? by w_stringer

w_stringer
Mon Jan 19 15:43:40 CST 2004

Hi Andrew,

The app is a custom medical application which appears to be written in
VB.

The problem I'm having is that when I use wscript.sleep...the app
hangs as well. So if I use wscript.sleep 5000 while I'm waiting for
the login window to appear...the app hangs and the login window
doesn't appear until after script execution stops. Thus AppActivate
fails. If I increase the sleep time to 10 seconds...it hangs for 10
seconds and as soon as the script stops...the window appears.

It's almost like the script and the app are using the same memory
space and are stepping on each other. That's why I was originally
asking about a way to force it to run in a separate thread or in its
own memory space.

Walt

"Andrew Hilton" <hiltona@ocean.com.au> wrote in message news:<uatpy1l3DHA.2296@TK2MSFTNGP11.phx.gbl>...
> What is the app that you are launching? This seems to be missing from your
> script.
>
> Use the 'Run' method to launch your exe, sleep for a while, then use
> AppActivate passing the window title of your app's main window. Don't advise
> using a loop. If you want more time, increase the value passed to
> wscript.sleep between objShell.Run and objShell.AppActivate.
>
> Andrew
>

Re: Is it possible to run a VBscript in its own memory space? by Michael

Michael
Tue Jan 20 13:19:40 CST 2004

Walt Stringer wrote:
> Hi Andrew,
>
> The app is a custom medical application which appears to be written in
> VB.
>
> The problem I'm having is that when I use wscript.sleep...the app
> hangs as well. So if I use wscript.sleep 5000 while I'm waiting for
> the login window to appear...the app hangs and the login window
> doesn't appear until after script execution stops. Thus AppActivate
> fails. If I increase the sleep time to 10 seconds...it hangs for 10
> seconds and as soon as the script stops...the window appears.
>
> It's almost like the script and the app are using the same memory
> space and are stepping on each other. That's why I was originally
> asking about a way to force it to run in a separate thread or in its
> own memory space.
>
> Walt
>
> "Andrew Hilton" <hiltona@ocean.com.au> wrote in message
> news:<uatpy1l3DHA.2296@TK2MSFTNGP11.phx.gbl>...
> > What is the app that you are launching? This seems to be missing
> > from your script.
> >
> > Use the 'Run' method to launch your exe, sleep for a while, then use
> > AppActivate passing the window title of your app's main window.
> > Don't advise using a loop. If you want more time, increase the
> > value passed to wscript.sleep between objShell.Run and
> > objShell.AppActivate.
> >
> > Andrew

I believe a workaround could be to have two scripts. One to do the app
activate and one to launch the application. Call the second script from the
first and have it do a quick run command, then when it exits you go into
your sleep/wait for the application. I had a similar issue and I think the
problem was the application was waiting on the parent window.

--
Regards,

Michael Holzemer
No email replies please - reply in newsgroup

Learn script faster by searching here
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp




Re: Is it possible to run a VBscript in its own memory space? by w_stringer

w_stringer
Thu Feb 05 12:20:09 CST 2004

Thanks for the advice...I'll give that a try.

>
> I believe a workaround could be to have two scripts. One to do the app
> activate and one to launch the application. Call the second script from the
> first and have it do a quick run command, then when it exits you go into
> your sleep/wait for the application. I had a similar issue and I think the
> problem was the application was waiting on the parent window.