Solved

Stopping a running app from VB

Posted on 1998-10-09
4
142 Views
Last Modified: 2010-04-30
I need to stop and restart (reboot) another application from within my VB app. For example, 'myapp' needs to stop stop MS Word and then restart it. Does anyone know the best way to do this?

Thanks
0
Comment
Question by:joe_s
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1439057
Get the HWND of the application, and send a close message :

Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_CLOSE = &H10&


Call PostMessage(nHWND, WM_CLOSE, NULL, NULL)

0
 
LVL 14

Expert Comment

by:waty
ID: 1439058
To find the hwn of the application :

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


   nHwnd = FindWindow("Your Program", vbNullString)

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1439059
Use "OpusApp" for word
0
 

Author Comment

by:joe_s
ID: 1439060
Thanks, That's just what I needed.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

786 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