|
-
Sep 21st, 2005, 09:21 PM
#1
Thread Starter
Lively Member
is "notepad.exe" running?
ok i need to know if a program is running or not lets say notpade.exe ............. anyone ?
-
Sep 21st, 2005, 09:25 PM
#2
Re: is "notepad.exe" running?
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
-
Sep 21st, 2005, 09:40 PM
#3
Re: is "notepad.exe" running?
Also, you may just be able to use the FindWindow API; if it return a 0, app not running.
However, |2eM!x's example is probably bullet proof 
And... is it your intension to check for an instance of 'your app' running? cause there is an inbuilf VB Function to take care of that.
-
Sep 22nd, 2005, 03:17 PM
#4
Thread Starter
Lively Member
Re: is "notepad.exe" running?
thanks |2eM!x...... works great
-
Sep 22nd, 2005, 03:45 PM
#5
Addicted Member
Re: is "notepad.exe" running?
yes why not use the findwindow API its easy
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
|