Results 1 to 5 of 5

Thread: is "notepad.exe" running?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Location
    earth
    Posts
    89

    is "notepad.exe" running?

    ok i need to know if a program is running or not lets say notpade.exe ............. anyone ?
    Aim: zhahaman2001

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: is "notepad.exe" running?

    module
    VB Code:
    1. Option Explicit
    2. Public strstr As String
    3. Const MAX_PATH& = 260
    4.  
    5. Declare Function ProcessFirst _
    6. Lib "kernel32" Alias "Process32First" _
    7. (ByVal hSnapshot As Long, _
    8. uProcess As PROCESSENTRY32) As Long
    9.  
    10. Declare Function ProcessNext _
    11. Lib "kernel32" Alias "Process32Next" _
    12. (ByVal hSnapshot As Long, _
    13. uProcess As PROCESSENTRY32) As Long
    14.  
    15. Declare Function CreateToolhelpSnapshot _
    16. Lib "kernel32" Alias "CreateToolhelp32Snapshot" _
    17. (ByVal lFlags As Long, _
    18. lProcessID As Long) As Long
    19.  
    20. Declare Function CloseHandle _
    21. Lib "kernel32" (ByVal hObject As Long) As Long
    22.  
    23. Type PROCESSENTRY32
    24.      dwSize As Long
    25.      cntUsage As Long
    26.      th32ProcessID As Long
    27.      th32DefaultHeapID As Long
    28.      th32ModuleID As Long
    29.      cntThreads As Long
    30.      th32ParentProcessID As Long
    31.      pcPriClassBase As Long
    32.      dwFlags As Long
    33.      szexeFile As String * MAX_PATH
    34. End Type
    35.  
    36. Public Function IsRunning(Exename As String) As Boolean
    37. Const TH32CS_SNAPPROCESS As Long = 2&
    38. Dim uProcess As PROCESSENTRY32
    39. Dim rProcessFound As Long
    40. Dim hSnapshot As Long
    41. Dim szExename As String
    42. Dim i As Integer
    43.  
    44. uProcess.dwSize = Len(uProcess)
    45. hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    46. rProcessFound = ProcessFirst(hSnapshot, uProcess)
    47. Do While rProcessFound
    48. i = InStr(1, uProcess.szexeFile, Chr(0))
    49. szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    50. rProcessFound = ProcessNext(hSnapshot, uProcess)
    51.     If InStr(LCase(szExename), LCase(Exename)) Then
    52.         IsRunning = True: Exit Do
    53.     End If
    54. Loop
    55. End Function

    call it like If IsRunning("notepad.exe")= true then

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Location
    earth
    Posts
    89

    Re: is "notepad.exe" running?

    thanks |2eM!x...... works great
    Aim: zhahaman2001

  5. #5
    Addicted Member jeroen_12's Avatar
    Join Date
    Jul 2005
    Posts
    152

    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
  •  



Click Here to Expand Forum to Full Width