Solved

API (VB6) for Closing a tray icon program

Posted on 2004-10-19
4
303 Views
Last Modified: 2012-08-14
My data provider recently changed their program from a "Windowed application" to just a system tray program.  I used to close the GUI program like this:

   lngWin = FindWindow(vbNullString, "TALNET")
   If lngWin <> 0 Then SendMessage lngWin, WM_CLOSE, 0&, 0&

But that doesn't work anymore because there is no window.  My provider emailed back:

"Using the Win32 SendMessage API was a good idea for an app that had a GUI window, as TALNET did.  Since TALDDE's just a tray icon, the logical analogy would be to find the Win32 API for sending a message to a tray icon"

Can anyone send me the code to close a program that is only running in the system tray?  The program is called "taldde32.exe" in the Processes tab of the Windows Task Manager.

 




0
Comment
Question by:LovinSpoonful
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 12349698
This can be done using WMI as follows:

Dim oProcess

For Each oProcess In GetObject("winmgmts:root\cimv2").ExecQuery("Select * from " & _
                    "Win32_Process Where Name = 'taldde32.exe'")

    oProcess.Terminate
    Debug.Print oProcess.Name & " was terminated..."

Next
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12349709
Try to find the process using API
Declare Function EnumProcesses Lib "PSAPI.DLL" (ByRef lpidProcess As Long, _
                                                                        ByVal cb As Long, _
                                                                        ByRef cbNeeded As Long) As Long


Then use

Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, _
                                                                                                               ByVal uExitCode As Long) As Long

to terminate the process
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12349782
I agree with Erick37
Nice solution!
0
 

Author Comment

by:LovinSpoonful
ID: 12369592
thank you Erick37.  
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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