|
-
October 4th, 2001, 09:54 AM
#1
Check if Application is running
Hello,
I have a VB application that launches another application from one of the menu items.
When unloading the form I would like to find out if the external application is running or not and then kill the external application only if it is running.
I have been successful in killing the application, I want to know how can I check if the external application is running or not.
Thanks
Harini
-
October 4th, 2001, 09:57 AM
#2
Re: Check if Application is running
Enumerate windows and see if the application is running. You can find window by its caption or fraction of the caption.
'---Bas module code------
Private Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam 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 Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetParent& Lib "user32" (ByVal hwnd As Long)
Dim sPattern As String, hFind As Long
Dim bFound As Boolean
Function EnumWinProc(ByVal Hwnd As Long, ByVal lParam As Long) As Long
'========================================================================
Dim k As Long, sName As String
If IsWindowVisible(Hwnd) And GetParent(Hwnd) = 0 Then
sName = Space$(128)
k = GetWindowText(Hwnd, sName, 128)
If k > 0 Then
sName = Left$(sName, k)
If lParam = 0 Then sName = UCase(sName)
If sName Like sPattern Then
hFind = Hwnd
EnumWinProc = 0
bFound = True
Exit Function
End If
End If
End If
EnumWinProc = 1
bFound = False
End Function
EnumWinProc = 1
End Function
Public Function FindWindowWild(sWild As String, Optional bMatchCase As Boolean = True) As Long
'========================================================================
sPattern = sWild
If Not bMatchCase Then sPattern = UCase(sPattern)
EnumWindows AddressOf EnumWinProc, bMatchCase
If bFound Then
FindWindowWild = hFind
Else
FindWindowWild = 0
End If
End Function
'----Using (Form code)----
Private Sub Command1_Click()
Debug.Print FindWindowWild("*Mi??OSoFt In[s-u]ernet*", False)
End Sub
Iouri Boutchkine
[email protected]
-
October 4th, 2001, 10:30 AM
#3
Re: Check if Application is running
Hello Iouri,
The code that u have sent works on the basis of WindowText. But the external application runs in the form of an icon in the task bar.
Please instruct me accordingly.
Thank u for the prompt reply
Thanks
Harini
-
October 4th, 2001, 12:23 PM
#4
Re: Check if Application is running
It is still a window. When you run your app, hit Ctrl-Alt_Del and see in the Task manager the name of its window. Then perform search of this window
Iouri Boutchkine
[email protected]
-
October 12th, 2001, 09:07 AM
#5
Re: Check if Application is running
I tried it and it works great. How would you implement the same functionality for checking a process a remote server?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|