Solved

API (VB6) for Closing a tray icon program

Posted on 2004-10-19
4
299 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now