Solved

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

Posted on 2003-12-08
6
233 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
  • 2
  • 2
6 Comments
 
LVL 85

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 20 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 85

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

860 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