Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close an open command prompt windows using VB when it has lost focus.

Posted on 2003-12-08
6
Medium Priority
?
241 Views
Last Modified: 2008-02-01
Hi expert,
i open a command prompt windows using vb. let say, the command prompt windows has lost its focus.. meaning that i cannot use sendkeys function to write command in it anymore.. so how i gonna close the command prompt windows? If it still in focus, i just sendkeys "exit" and it will close. But since it lost focus, sendkeys won't work.

thanks..
0
Comment
Question by:Diode_Temp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9896633
Store the AppID returned from your Shell() call.   Then you can use the AppActivate() function to return focus to the window each you want to use SendKeys().

Option Explicit

Dim MyAppID As Double

Private Sub Command1_Click()
    AppActivate MyAppID
    SendKeys "dir~", True
End Sub

Private Sub Form_Load()
    MyAppID = Shell("command.com", 1)
End Sub
0
 

Accepted Solution

by:
mr_avril earned 80 total points
ID: 9908653
i have tried your code.. but it seem like VB cannot close the command prompt windows. it give command prompt windows a focus but it cannot close it.
using the sendkeys u use in your code.. it give something like this in the command prompt windows..

C:\PROGRA~1\MICROS~3\VB98>\
                                                 \
                                                 \
                                                 \
0
 

Expert Comment

by:mr_avril
ID: 9909264
i change this..
Private Sub Form_Load()
    MyAppID = Shell("command.com", 1)
End Sub

to this..

Private Sub Form_Load()
    MyAppID = Shell("cmd", 1)
End Sub
  and it works fine.. anyway thanks..
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9909548
Glad you got it to work.  The main point was using AppActivate to give it focus before sending the keys.
0
 
LVL 27

Expert Comment

by:planocz
ID: 10217813
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from Diode_Temp from 12/09/2003 comment
Award points to mr_avril is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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