Solved

API (VB6) for Closing a tray icon program

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

739 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