Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping a Windows App using VB

Status
Not open for further replies.

Coop3DW

MIS
Mar 14, 2002
7
US
Is there a way to stop an application (Windows Media Player) using VB?

I’m using a CAD modeling package that generates models in batch mode to an avi file format(10-30 at a time). Unfortunately the modeling software we’re using automatically starts Windows Media Player after each avi file is created and there’s no way to stop this within the modeling software. I would like to create a little VB app that I can call within my modeling batch program after each avi is created to kill the media player app if it’s running.

Any ideas would be greatly appreciated!

Thanks!
 
you can go here and research "FindWindow" and "DestroyWindow" Sorry I'm just killing time and am not near any of my resources to give you more info. FindowWindow needs the exact windows title, which might give you a little extra work if your .CAD files have variable names and windows media player puts that name in the title bar. Also I think I tried DestroyWindow on XP and it didn't work. So you might have to find an alternative way of closing the window on XP. FindWindow and Destroy Window in a Timer should work for you.
 
If your mediaplayer gets the focus when playing then you can try &quot;Sendkeys&quot; to send it an <alt>[F4]. No need for API but it only works if Mediaplayer becomes topmost.
come to think of it, you probably could MAKE it get the focus with &quot;appactivate&quot;.
 
Thanks for the suggestions. I’m most likely going to go the API route. This at least gives me a starting point.

Thanks again to you both!
 
FindWindow will identify the main window of the app. Then SendMessage WM_CLOSE to that window.

Do not be tempted to use TerminateProcess which just kills the process and doesn't clean up properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top