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

Is a program running?

Status
Not open for further replies.

gvt

Programmer
Jul 19, 2000
14
SE
I would like to to find out if, for instance, Explorer or Netscape is already running. I have heard that&nbsp;&nbsp;FindWindow API function can be used to search for the Window Title specified but the problem is that the Window Title can change depending on the site or file name which is open. Is there a way to go around this? <br>I have also heard that something called &quot;App&quot;&nbsp;&nbsp;can be used instead but unfortunately I can not find any example about this App on VB help topics. <br>If you know anything about these or any other way to find out if a program is already running please let me know. <br><br>Thank you for your time and effort. <br><br>&nbsp;&nbsp;Vio
 
hello fella

you are right on your info with findwindow()
you must be knowing that a handle to a window can change but the clss from which it is derived always remains the same.
to get the classname of a window use Getclassname() win32api call
Public Declare Function GetClassName Lib &quot;user32&quot; Alias &quot;GetClassNameA&quot; (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
then use this classname as the first parameter with findwindow() and keep the second parameter as NULL(0&amp;) to find whether the application whose window is derived from the specified class is running
eg ; classname of vbform is ThunderFormDC,of Notepad is &quot;Notepad&quot;

bye aniket
hope its of use to u now
 
faq222-61 describes a method to retrieve the path to all running EXE's. This is a good way to find out what is actually running while ignoring the window titles.

Alas, I don't think it will work under NT.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
The following code WILL work in NT:


Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
'*** EnumWindows API Function ***
Static CompareText As String
Static WindowText As String
Static nRet As Long

'*** Make sure we meet visibility requirements ***
If (IsWindowVisible(hWnd)) Then
'*** It shouldn't have any parent window, either ***
If (GetParent(hWnd) = 0) Then
'*** And, finally, it shouldn't have an owner ***
If (GetWindowLong(hWnd, GWL_HWNDPARENT) = 0) Then
'*** Retrieve window caption ***
WindowText = Space$(256)
nRet = GetWindowText(hWnd, WindowText, Len(WindowText))
If (nRet) Then
'*** Clean up window text and add to list ***
CompareText = Left$(WindowText, nRet)
If (CompareText = WinApp) Then
IsAppRunning = &quot;true&quot;
Debug.Print WinApp &amp; &quot; is active @ &quot; &amp; Time
End If
WindowText = hWnd &amp; &quot; - &quot; &amp; Left$(WindowText, nRet)
End If
End If
End If
End If

'*** Return True to continue enumeration ***
EnumWindowsProc = True
End Function


Just replace the window name in WinApp with the name of the window you are looking for.
Brett Please visit my websites!
 
Clever! Check for windows without a parent....
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top