?
Solved

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

Posted on 2003-12-08
6
Medium Priority
?
238 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

752 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