check if app. is running
Page 1 of 1 • Share •
check if app. is running
to check if app. is running
- Code:
Option Explicit
Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
Private Const STILL_ACTIVE As Long = &H103
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Sub Form_Load()
Dim lPid As Long
lPid = Shell("notepad.exe", vbNormalFocus)
Debug.Print IsAppRunning(lPid)
End Sub
Private Function IsAppRunning(ByVal lProgID As Long) As Boolean
Dim lhProc As Long
Dim lRet As Long
lhProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, lProgID)
If Not lhProc = 0 Then
Call GetExitCodeProcess(lhProc, lRet)
Call CloseHandle(lhProc)
IsAppRunning = (lRet = STILL_ACTIVE)
End If
End Function

~Fleck- Moderator

- Posts: 274
Activity: -258
Reputation: 8
Join date: 2009-06-28
Age: 16
Location: 127.0.0.1
Re: check if app. is running
with mutex
- Code:
'Megrem
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (ByVal lpMutexAttributes As Long, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const ERROR_ALREADY_EXISTS = 183&
Public Function CheckMutex(strMutex As String) As Boolean
Dim mutexvalue As Long
mutexvalue = CreateMutex(ByVal 0&, 1, strMutex)
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
CheckMutex = True
CloseHandle mutexvalue
Else
CheckMutex = False
End If
End Function
_________________

Thanks to FusioN for this awesome sig :]

~Fleck- Moderator

- Posts: 274
Activity: -258
Reputation: 8
Join date: 2009-06-28
Age: 16
Location: 127.0.0.1
Permissions of this forum:
You cannot reply to topics in this forum
Home




