INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Only find applications visible on the Taskbar?

Only find applications visible on the Taskbar?

(OP)
I'm using Solution 2 from this faq:
http://www.tek-tips.com/faqs.cfm?fid=61

Can I modify it to only fill the list with applications which are visible on the Taskbar rather than all EXEs?

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?

RE: Only find applications visible on the Taskbar?

Sure sounds like you're trying to create spyware. I can't think of a legitimate reason for this. Maybe you can offer a hint?

RE: Only find applications visible on the Taskbar?

(OP)
A friend of mine wants a utility which will close an application if it's open for more than 20 minutes (his application links to a wireless camera via a satellite link and people in the office keep forgetting to close the link which racks up a big phone bill). I've already written the app and it works fine, it's just that it lists all the processes rather than just the ones which appear on the "Applications" tab in Task Manager. I simply wanted to narrow the list down to the 'major' applications.

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?

RE: Only find applications visible on the Taskbar?

Well I don't think it's easy, and in any case it may vary by version of Windows. Changes were definately made in Vista and then again in Windows 7.

Everything I can find (which isn't much) points back to Which windows appear in the Alt+Tab list?

RE: Only find applications visible on the Taskbar?

These two are not the same:

>just the ones which appear on the "Applications" tab in Task Manager
>applications which are visible on the Taskbar

Which do you want? The latter is trickier, but if the former, then something like the following should work:

CODE

Option Explicit

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Const GW_OWNER = 4
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000

Public Sub Main()
   EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub

Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
     Dim sSave As String, Ret As Long
     sSave = Space(255)
     Ret = GetWindowText(hWnd, sSave, 255)
     If Ret And (GetWindow(hWnd, GW_OWNER) = 0) And ((GetWindowLong(hWnd, GWL_STYLE) And WS_VISIBLE) <> 0) Then Debug.Print Left(sSave, Ret)
     ' continue enumeration
     EnumWindowsProc = True
End Function 

RE: Only find applications visible on the Taskbar?

Do all the apps use a particular DLL? Have a look at EnumProcesses and EnumProcessModules. You can then pick out the ones that use specific DLLs or specific process names and kill them off.

RE: Only find applications visible on the Taskbar?

(OP)
Thanks strongm - is it possible to reveal the name of EXE rather than the caption of the window? So for example it would return Firefox.exe rather than "Visual Basic(Microsoft): Version 5 & 6 - Only find applications visible on the Taskbar?". Sorry I didn't make that clear in my original question but the FAQ to which I referred returns the names of the EXEs and I want to narrow that list down to the EXEs listed by your code above.

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?

RE: Only find applications visible on the Taskbar?

2
Sure. You just need this function; just pass it the hWnd and it'll return the associated executablepath:

CODE

Option Explicit
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long

Public Function GetModuleName(hWnd As Long) As String
    Dim objWMIService As Object
    Dim colItems As Object
    Dim oProcess As Object
    Dim result As Long
    Dim lPID As Long
    
    result = GetWindowThreadProcessId(hWnd, lPID) ' we want process associated with window
       
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.execquery("select * from Win32_Process where ProcessID = " & lPID)

    ' there'll be 0 or 1 result
    For Each oProcess In colItems
        GetModuleName = oProcess.executablepath
    Next

End Function 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close