bigracefan
Programmer
I'm using the following code to start up applications that have shut down:
Private Sub Verify_Running()
Dim i As Integer
Dim AppName(20) As String
Dim MyAppInstances As Integer
For i = 0 To lstRequired.ListCount - 1
AppName(i) = ReportArray2(i)
piAppCount = 0
MyAppInstances = AppInstances(Get_Title(UCase(AppName(i))), False)
If MyAppInstances = 0 Then
Run_Required (AppName(i))
End If
Next
End Sub
Public Function AppInstances(AppNamePart As String, _
Optional ExactMatchOnly As Boolean) As Integer
'PURPOSE: Counts the Number of Instances of a Given Application
'PARAMETERS:
'AppNamePart = Any Part of the WindowTitle for the App
'ExactMatchOnly (Optional): If you want to
'count only exact matches for AppNamePart,
'set this parameter to true
'RETURNS: Number of Running Instances
'EXAMPLE:
'dim iIEInstances as integer
'piAppCount = 0
'iIEInstances = AppInstances("Microsoft Internet Explorer")
Dim lRet As Long
psAppString = AppNamePart
pbExact = ExactMatchOnly
lRet = EnumWindows(AddressOf CheckForInstance, 0)
AppInstances = piAppCount
End Function
Private Function CheckForInstance(ByVal lhWnd As Long, ByVal _
lParam As Long) As Long
Dim sTitle As String
Dim lRet As Long
Dim iNew As Integer
sTitle = Space(255)
lRet = GetWindowText(lhWnd, sTitle, 255)
sTitle = StripNull(sTitle)
If sTitle <> "" Then
If pbExact Then
If sTitle = psAppString Then piAppCount = piAppCount + 1
Else
If InStr(sTitle, psAppString) > 0 Then _
piAppCount = piAppCount + 1
End If
End If
CheckForInstance = True
End Function
Private Function StripNull(ByVal InString As String) As String
'Input: String containing null terminator (Chr(0))
'Returns: all character before the null terminator
Dim iNull As Integer
If Len(InString) > 0 Then
iNull = InStr(InString, vbNullChar)
Select Case iNull
Case 0
StripNull = InString
Case 1
StripNull = ""
Case Else
StripNull = Left$(InString, iNull - 1)
End Select
End If
End Function
This application has a listbox of the applications that need to be running. I would now like to shut down the appliations. Is there a way to do this using lhWnd?
Or, is there a way to shut down the applications that I have in my listbox.
Thanks.
Private Sub Verify_Running()
Dim i As Integer
Dim AppName(20) As String
Dim MyAppInstances As Integer
For i = 0 To lstRequired.ListCount - 1
AppName(i) = ReportArray2(i)
piAppCount = 0
MyAppInstances = AppInstances(Get_Title(UCase(AppName(i))), False)
If MyAppInstances = 0 Then
Run_Required (AppName(i))
End If
Next
End Sub
Public Function AppInstances(AppNamePart As String, _
Optional ExactMatchOnly As Boolean) As Integer
'PURPOSE: Counts the Number of Instances of a Given Application
'PARAMETERS:
'AppNamePart = Any Part of the WindowTitle for the App
'ExactMatchOnly (Optional): If you want to
'count only exact matches for AppNamePart,
'set this parameter to true
'RETURNS: Number of Running Instances
'EXAMPLE:
'dim iIEInstances as integer
'piAppCount = 0
'iIEInstances = AppInstances("Microsoft Internet Explorer")
Dim lRet As Long
psAppString = AppNamePart
pbExact = ExactMatchOnly
lRet = EnumWindows(AddressOf CheckForInstance, 0)
AppInstances = piAppCount
End Function
Private Function CheckForInstance(ByVal lhWnd As Long, ByVal _
lParam As Long) As Long
Dim sTitle As String
Dim lRet As Long
Dim iNew As Integer
sTitle = Space(255)
lRet = GetWindowText(lhWnd, sTitle, 255)
sTitle = StripNull(sTitle)
If sTitle <> "" Then
If pbExact Then
If sTitle = psAppString Then piAppCount = piAppCount + 1
Else
If InStr(sTitle, psAppString) > 0 Then _
piAppCount = piAppCount + 1
End If
End If
CheckForInstance = True
End Function
Private Function StripNull(ByVal InString As String) As String
'Input: String containing null terminator (Chr(0))
'Returns: all character before the null terminator
Dim iNull As Integer
If Len(InString) > 0 Then
iNull = InStr(InString, vbNullChar)
Select Case iNull
Case 0
StripNull = InString
Case 1
StripNull = ""
Case Else
StripNull = Left$(InString, iNull - 1)
End Select
End If
End Function
This application has a listbox of the applications that need to be running. I would now like to shut down the appliations. Is there a way to do this using lhWnd?
Or, is there a way to shut down the applications that I have in my listbox.
Thanks.