module
VB Code:
Option Explicit Public strstr As String Const MAX_PATH& = 260 Declare Function ProcessFirst _ Lib "kernel32" Alias "Process32First" _ (ByVal hSnapshot As Long, _ uProcess As PROCESSENTRY32) As Long Declare Function ProcessNext _ Lib "kernel32" Alias "Process32Next" _ (ByVal hSnapshot As Long, _ uProcess As PROCESSENTRY32) As Long Declare Function CreateToolhelpSnapshot _ Lib "kernel32" Alias "CreateToolhelp32Snapshot" _ (ByVal lFlags As Long, _ lProcessID As Long) As Long Declare Function CloseHandle _ Lib "kernel32" (ByVal hObject As Long) As Long Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szexeFile As String * MAX_PATH End Type Public Function IsRunning(Exename As String) As Boolean Const TH32CS_SNAPPROCESS As Long = 2& Dim uProcess As PROCESSENTRY32 Dim rProcessFound As Long Dim hSnapshot As Long Dim szExename As String Dim i As Integer uProcess.dwSize = Len(uProcess) hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) rProcessFound = ProcessFirst(hSnapshot, uProcess) Do While rProcessFound i = InStr(1, uProcess.szexeFile, Chr(0)) szExename = LCase$(Left$(uProcess.szexeFile, i - 1)) rProcessFound = ProcessNext(hSnapshot, uProcess) If InStr(LCase(szExename), LCase(Exename)) Then IsRunning = True: Exit Do End If Loop End Function
call it like If IsRunning("notepad.exe")= true then





Reply With Quote