Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find out if an app is running

10 views
Skip to first unread message

Unknown

unread,
Mar 13, 2001, 12:40:12 PM3/13/01
to
I have an app that is external to Word that we have been using with
Word95. There is a command in WordBasic called AppIsRunning that we
use to see if the app is already running and if not to start it.

I can't find a similar command in Word97 VBA. Do I need to use the
FindWindow API? I'd rather not do this if there is some built-in
command.

Thanks in advance,

Mike

Unknown

unread,
Mar 13, 2001, 1:28:22 PM3/13/01
to
I forgot to mention that the caption of the window changes, so I will
have a hard time finding the window unless I use enumeration, which I
can't figure out how to do without the AddressOf operator, which does
not appear to exist in Word97 VBA.

I can't use the classname either because this is a VB app and there
are more than one of them running, so again I would have to use
enumeration.

Any help would be greatly, greatly appreciated.

Thanks,

Mike

Dave Rado

unread,
Mar 13, 2001, 6:20:38 PM3/13/01
to
Look into If Tasks("whatever").Exists Then

Regards

Dave

<Michael Stephenson> wrote in message
news:3aae5b12....@news.mindspring.com...

gwk

unread,
Mar 13, 2001, 10:00:46 PM3/13/01
to
Michael:

This is a roundabout way, but I used the following function to determine if
the Worldox executable was running.

You should be able to alter it easily for your purpose.

g-
gwk...@hotmail.com


**** Code Begins Here ****

'********************************************************
'*The Blackstone Group *
'*The Publishing Group *
'*Created by George W. Kenny - gwk...@yahoo.com *
'*Date of Creation: December 2000 *
'*Modified by: George W. Kenny *
'*Date of Last Modification: December 2000 *
'********************************************************

'DESC: Module that holds my procedures that corrects Worldox's incorrect
programming regarding
' saving and exiting - gwk

Option Explicit

'Functions for Worldox Open function
Public Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As
Long, ByVal lngSize As Long, _
ByRef lngSizeNeeded As Long) As Long
Public Declare Function OpenProcess Lib "Kernel32.dll" (ByVal
dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _
ByVal dwProcId As Long) As Long
Public Declare Function EnumProcessModules Lib "psapi.dll" (ByVal
lng_hProcess As Long, ByRef lphModule As Long, _
ByVal lngSize As Long, ByRef lngSizeNeeded As Long) As Long
Public Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal
lng_hProcess As Long, ByVal hModule As Long, _
ByVal strModuleName As String, ByVal lng_n_Size As Long) As Long
Public Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As
Long) As Long

Function WorldoxOpen()
'DESC: Procedure returns all the processes currently running and checks to
see if WDNT.EXE (Worldox) is up

Const PROCESS_QUERY_INFORMATION = 1024
Const PROCESS_VM_READ = 16
Const MAX_PATH = 260

Dim lngSize As Long
Dim lngSizeNeeded As Long
Dim lngNumElem As Long
Dim lngProcessIDs() As Long
Dim lngSizeNeeded2 As Long
Dim lngModules(1 To 200) As Long
Dim lngRet As Long
Dim strModuleName As String
Dim lng_n_Size As Long
Dim lng_hProcess As Long
Dim lngCounter As Long

WorldoxOpen = False

lngSize = 8
lngSizeNeeded = 96
'Define necessary array size
Do While lngSize <= lngSizeNeeded
lngSize = lngSize * 2
ReDim lngProcessIDs(lngSize / 4) As Long
lngRet = EnumProcesses(lngProcessIDs(1), lngSize, lngSizeNeeded)
Loop
lngNumElem = lngSizeNeeded / 4

'Cycle through each process
For lngCounter = 1 To lngNumElem
'Get the handle
lng_hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or
PROCESS_VM_READ, 0, lngProcessIDs(lngCounter))
'Return the name of the process if valid
If lng_hProcess <> 0 Then
lngRet = EnumProcessModules(lng_hProcess, lngModules(1), 200,
lngSizeNeeded2)
If lngRet <> 0 Then
strModuleName = Space(MAX_PATH)
lng_n_Size = 500
lngRet = GetModuleFileNameExA(lng_hProcess, lngModules(1),
strModuleName, lng_n_Size)
'Test if Worldox is open
If LCase(Left(strModuleName, lngRet)) =
"c:\worldox\wdnt.exe" Then
WorldoxOpen = True
End If
End If
End If
'Close the handle to the process
lngRet = CloseHandle(lng_hProcess)
Next
End Function

Dave Rado <dr...@onetel.net.uk> wrote in message
news:O2MCLSBrAHA.1840@tkmsftngp03...

0 new messages