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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if other apps are running

Status
Not open for further replies.

twix79

IS-IT--Management
Apr 5, 2002
110
US
I would like to create an application which is able to monitor other VB applications on the PC and detect when they stop. So far, I have been unable to find any commands which are able to monitor an app other than the app that contains these commands. Is there a way to do this?

Any help would be greatly appreciated.
 
Forgot to add that I am running VB5 on a Windows NT 4.0 service pack 6.
 
Try this API fuction. It will return the app's handle if the specified title/classname is found

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

· hwndParent
Identifies the parent window whose child windows are to be searched.
If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.

· hwndChildAfter
Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.

· lpszClass
Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero.

· lpszWindow
Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.
 
Thanks for the help. I do have one more question though, when I call the function, what do I use as the arguments? Thanks.
 
I have some code that you can send an exe name to and it tells if it is running or not and returns the hwnd of the program if it is.

Are you interested in this, or the other? If you want this let me know and I can get it to you tomorrow.
 
If you want to monitor just other visual basic applications, you could indeed use findwindowex. Every visual basic application has a hidden window with the same classname, so findwindowex wont fail. If you find all these windows, you have all applications running from visual basic. The only problem is that the different versions of visual basic have different classnames. The classname for visual basic 6 is "ThunderRT6Main". So if you want to print all the applications currently running compiled from Visual Basic 6 you would have something like this:

[tt]
Option Explicit

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Sub Form_Load()

Dim hWnd As Long
Dim sBuffer As String
Dim lReturn As Long

Form1.Show

Do

hWnd = FindWindowEx(0, hWnd, "ThunderRT6Main", vbNullString)
If hWnd = 0 Then Exit Do

sBuffer = Space$(255)
lReturn = GetWindowText(hWnd, sBuffer, Len(sBuffer))
Print Left$(sBuffer, lReturn)

Loop

End Sub
[/tt]
 
Thanks for the help LuckyLuke, but do you happen to know the classname for visual basic 5, which is what I have written my programs in? Thanks.
 
I don't know for sure, but I guess it's "ThunderRT5Main". To find out for sure do the following:

- Compile an exe and run it.
- Launch Spy++ (its shipped with visual studio)
- Search in that window for your application (behind it is the name of the class)
- There are 2 names, this is because one of the 2 is the hidden one. To find out which is the hidden one, it has the Project name as it's Windowtext.

With this powerfull tool you can find out ALL classes of EACH window in Windows. It even shows what WindowStyles a window is using. You should try playing with it a bit ;-)

LuCkY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top