Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opened an external app using the shell command how do I close it?

Posted on 2004-03-28
4
Medium Priority
?
1,139 Views
Last Modified: 2010-05-01
Can I close another external app from VB. I use the shell command to open it.
0
Comment
Question by:Sparky191
[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
4 Comments
 
LVL 4

Assisted Solution

by:xassets
xassets earned 200 total points
ID: 10698377
Use the FindWindow API function to get its hWND

Then send it a WM_CLOSE message using the SendMessage or PostMessage API Function
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 200 total points
ID: 10698396
0
 
LVL 4

Expert Comment

by:xassets
ID: 10698402
Yeah thats a bit more up to date.
0
 
LVL 6

Accepted Solution

by:
___XXX_X_XXX___ earned 600 total points
ID: 10698515
Shell returns to you process ID for created process. You can use this PID later in TerminateProcess to terminate program.

Like this:


In declarations section of your form:

Dim mlngPID As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long


 ' Add two command buttons - Command1 for start Calculator and Command2 for Terminating it.
Private Sub Command1_Click()
mlngPID = Shell("calc.exe")
End Sub


Private Sub Command2_Click()
Dim lngProcess As Long
lngProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, mlngPID)
TerminateProcess lngProcess, 0&
End Sub



Start project, press Command1 - calculator must show, then press command2 - calculator will be terminated.

Enjoy.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
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

722 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