VB Shell Command Opens Multiple Application Windows

Posted on 2003-02-19
Medium Priority
Last Modified: 2013-12-25

I've created a small application in VB5 to automatically ftp some data that I require weekly.

I use the Shell(pathname, [WindowNormalFocus]) command to open msdos prompt then SendKeys to type in the relevant data in the same way that this guy did:
(I think he's doing essentially the same thing as me).

The problem is sometimes it opens up 20 or so additional windows of msdos prompt for no obvious reason.  I don't have any wacky commands in there.  Can anyone think why or better yet how I can avoid it?  I was looking at the message boards and thought this might provide the answer:


Can someone confirm this?
Thanks (PS I'm new and not much of a programmer)
Question by:griffithsk
  • 3
  • 2
LVL 16

Accepted Solution

twalgrave earned 320 total points
ID: 7985163
If it's opening several DOS windows it is probably because you are calling shell several times.  Instead, use shell, get the return value, and use appactivate to activate the same window.  For instance:

dim lDosWindow as long
lDowWindow = shell("whatever")

appactivate lDosWindow
Sendkeys "This is a test"

appactivate lDosWindow
SendKeys "This is another test"


Author Comment

ID: 7986030
Sorry, that's not it, I'm not even using AppActivate, because I only have to send one set of keystrokes, so the code goes (something like as I don't have it with me):

variable = Shell ("c:\windows\sytem32\cmd.exe", vbnormalfocus)
sendkeys ""blah blah blah"

Then the subroutine ends (except for the error routines).  It's a really basic process (which makes it all the more frustrating when it doesn't work).

Even better, yesterday for some reason it was looping the Sendkeys statement within the DOS window, and I don't have any loop or dowhile/until statements in there.

Author Comment

ID: 7988003
But don't worry about that, that's only happened once and it's not too much of an issue.

Author Comment

ID: 8680447
You may as well have the points, it's not the answer and the problrm hasn't been resolved but I want to close this and delete isn't an option.  Thanks for trying though!!
LVL 16

Expert Comment

ID: 8684885
Thank you!  I wish I could have been more help.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

578 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